小编Tim*_*imo的帖子

将命名参数传递给 shell 脚本

有没有什么简单的方法可以将命名参数传递(接收)给 shell 脚本?

例如,

my_script -p_out '/some/path' -arg_1 '5'
Run Code Online (Sandbox Code Playgroud)

并在内部my_script.sh将它们接收为:

# I believe this notation does not work, but is there anything close to it?
p_out=$ARGUMENTS['p_out']
arg1=$ARGUMENTS['arg_1']

printf "The Argument p_out is %s" "$p_out"
printf "The Argument arg_1 is %s" "$arg1"
Run Code Online (Sandbox Code Playgroud)

这在 Bash 或 Zsh 中可能吗?

bash zsh shell-script arguments

192
推荐指数
8
解决办法
28万
查看次数

标签 统计

arguments ×1

bash ×1

shell-script ×1

zsh ×1