gpt4 book ai didi

arrays - 将相同类型的命令行参数读入Powershell中的数组/哈希

转载 作者:行者123 更新时间:2023-12-03 01:19:22 27 4
gpt4 key购买 nike

如何将Powershell中的命令行参数读入数组?就像是

myprogram -file file1 -file file2 -file file3

然后我有一个数组
[file1,file2,file3]

类似的哈希问题。
谢谢。

最佳答案

命令行参数默认情况下存储在数组中。数组是$ args []。如果要命名参数,请使用param()。如果要为同一参数指定多个参数,请使用逗号。

示例代码:

function myprogram {
param (
[string[]]$file
)
#Do stuff to $file array here
}

命令行:
myprogram -file file1,file2,file3

关于arrays - 将相同类型的命令行参数读入Powershell中的数组/哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190719/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com