如何使用ZSH中第一个命令行参数的空间划界内容设置命令行arg
我将在我编写的脚本中获得一个命令行参数,这本身将是实际命令行参数的空间界定列表。我想用这些参数设置当前脚本的参数。我将如何实现这一目标?
我想使用设置 -
,但我不确定这将如何工作。
例如 给出我脚本的论点:-a -b -c
echo $1 # prints "-a -b -c"
I will be getting one command line argument in the script I'm writing which will itself be a space delimited list of the actual command line arguments. I'd like to set the arguments of the current script with these arguments. How might I accomplish that?
I'd like to use set --
but I'm not sure how this would work.
E.g.
Given arguments to my script: -a -b -c
echo $1 # prints "-a -b -c"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
设置 - “ $ {(z)1}”
。这将把$ 1
分为单词,处理以相同的方式进行引用:如果您还想删除报价级别,请使用
“ $ {(@q)$ {(z) )1}}“
。You can do this with
set -- "${(z)1}"
. This will split$1
into words, handling quoting the same way the shell itself does:If you also want to remove a level of quotes, use
"${(@Q)${(z)1}}"
instead.