Skip to content

Slice array with negative indexes's get the unlogic result's #20497

@LutAle

Description

@LutAle

Prerequisites

Steps to reproduce

I'm build grab docker cli string output with slicing waste header and processing remain string as need.
I is assumed that index -1 point last element in array, that is convenience.
But with reverse index i get items in reverse order, with garbage string header the it need drop.
Assumed that Array[0..Count] and slice operator [1..-1] produce sequence item's in direct odrder's [1], [2], [3], ... [Count] , but it in real case has output that slice with reverce item order [1], ... [0], [Count]
This operation rotate item sequence in buckward dirrection

Expected behavior

PS:\user>docker ps
CONTAINER ID   IMAGE              COMMAND     CREATED        STATUS        PORTS     NAMES
230d25385033   python:3.12-slim   "bash"      32 hours ago   Up 32 hours             pedantic_herschel
3f4b28c315cd   neovim             "sh"        37 hours ago   Up 37 hours             xenodochial_murdock
8b88e3fa3e4a   alpine             "/bin/sh"   47 hours ago   Up 47 hours             zen_meninsky

PS:\user>(docker ps)[1..-1]
230d25385033   python:3.12-slim   "bash"      32 hours ago   Up 32 hours             pedantic_herschel
3f4b28c315cd   neovim             "sh"        37 hours ago   Up 37 hours             xenodochial_murdock
8b88e3fa3e4a   alpine             "/bin/sh"   47 hours ago   Up 47 hours             zen_meninsky

For buil command like: (docker ps)[1..-1]  |  % {docker stop $_.Split(' ')[0]}
I get:
PS:\user>(docker ps)[1..-1] | % {$_.Split(' ')[0]}
230d25385033
CONTAINER
8b88e3fa3e4a

Actual behavior

PS:\user>(docker ps)[1..-1]
230d25385033   python:3.12-slim   "bash"      33 hours ago   Up 33 hours             pedantic_herschel
CONTAINER ID   IMAGE              COMMAND     CREATED        STATUS        PORTS     NAMES
8b88e3fa3e4a   alpine             "/bin/sh"   2 days ago     Up 2 days               zen_meninsky

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.6
PSEdition                      Core
GitCommitId                    7.4.0-preview.6
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-By DesignThe reported behavior is by design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions