Powershell 对使用-ReadCount的Get内容进行切片的意义是什么?

Powershell 对使用-ReadCount的Get内容进行切片的意义是什么?,powershell,Powershell,我试图理解在获取内容时使用-ReadCount的意义和效果。[3..5]为什么不生成(3,4,5)的数组?这个符号是什么意思 PS C:\src\t> (1..40) | Set-Content numbers.txt PS C:\src\t> (Get-Content .\numbers.txt -ReadCount 5)[3..5] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 PS C:\src\t> (Get-Content

我试图理解在获取内容时使用-ReadCount的意义和效果。[3..5]为什么不生成(3,4,5)的数组?这个符号是什么意思

PS C:\src\t> (1..40) | Set-Content numbers.txt
PS C:\src\t> (Get-Content .\numbers.txt -ReadCount 5)[3..5]
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
PS C:\src\t> (Get-Content .\numbers.txt -ReadCount 5)[3..4]
16
17
18
19
20
21
22
23
24
25
  • -ReadCount
    对通过管道的总行数没有影响

  • 相反,它决定一次传递多少行,作为一个数组;换句话说:这是一种分块机制

因此,使用
-ReadCount 5
,一次5行的数组通过管道,并且
[3..5]
因此通过第6个数组选择第4个数组,即3个5元素数组;因为它们只是输出到屏幕上,这3个数组看起来是一个平面数组,但它们不是

例如,要获取5元素输出数组中的第二个数组,请使用:

PS> (Get-Content .\numbers.txt -ReadCount 5)[1]
6
7
8
9
10
请注意,
-ReadCount 0
会将所有输入行作为单个
[object[]]
数组通过管道传递