Bash 如何使用我得到的参数执行程序?
我有一些脚本a.py,可以用一些参数执行它Bash 如何使用我得到的参数执行程序?,bash,Bash,我有一些脚本a.py,可以用一些参数执行它 ./a.py 1 2 --h 'Hi!' 我还有bash脚本sh.sh。我想这样做: ./sh.sh ./a.py 1 2 --h 'Hi!' 然后a.py从这些参数开始。如果您运行命令,我应该在sh.sh中写什么?: ./sh.sh ./a.py 1 2 --h 'Hi!' 然后在shell脚本中,数组$@的内容将是: './a.py' '1' '2' '--h' 'Hi!' 因此,如果您想运行该功能,您可以使用: "$@" 下面是shel
./a.py 1 2 --h 'Hi!'
我还有bash脚本sh.sh
。我想这样做:
./sh.sh ./a.py 1 2 --h 'Hi!'
然后
a.py
从这些参数开始。如果您运行命令,我应该在sh.sh
中写什么?:
./sh.sh ./a.py 1 2 --h 'Hi!'
然后在shell脚本中,数组$@
的内容将是:
'./a.py' '1' '2' '--h' 'Hi!'
因此,如果您想运行该功能,您可以使用:
"$@"
下面是shell提供的特殊变量列表,您可以在shell脚本中直接使用这些变量
Variable Variable Details
$# : Total number of arguments passed to script
$0 : Script name itself
$1 to $n : $1 for the first arguments, $2 for second argument till $n for n’th arguments. From 10’th argument, we must enclose them in curly braces eg. ${10}, ${11}
$* : Values of all the arguments. All agruments are double quoted
$@ : Values of all the arguments
$? : Exit status id of last command
$$ : Process ID of current shell
$! : Process id of last command
这里有一个非常简单的例子:)