如何从bash读取参数 [英] How to read arguments from bash
本文介绍了如何从bash读取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇如何通过终端将参数传递给bash脚本并读取它们并根据参数处理脚本函数.
I am curious as to how to pass in arguments via terminal to the bash script and read them and process the script functions based on the arguments.
所以,如果我做了类似的事情:
So if I did something like:
./scriptname.sh install
#or
./scriptname.sh assets install
我怎么说,好的,第一个参数安装了某些东西,而第二个参数则根据第一个参数执行了其他操作.
How would I say, ok the first argument installs something, while the second sais to do something else based on the first argument.
推荐答案
$0 is the name of the command
$1 first parameter
$2 second parameter
$3 third parameter etc. etc
$# total number of parameters
for args in $*
blah blah
这篇关于如何从bash读取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文