[英]Passing arguments to a shell script
I want to execute a shell script using usage()
in the script. 我想使用脚本中的
usage()
执行shell脚本。
I have to give three parameters in the usage block like below: 我必须在用法块中提供三个参数,如下所示:
./script_name server_name path flag
How do I write the code block for this? 我该如何编写代码块?
Finally, I need to read all the three parameters in a line to execute a jar file. 最后,我需要读取一行中的所有三个参数才能执行jar文件。
once you pass parameters you can access them with $1, $2 ... $n and $@ to get everything at once. 传递参数后,您可以使用$ 1,$ 2 ... $ n和$ @来访问它们,以一次获取所有内容。
./script_name server_name path flag
In the script code 在脚本代码中
echo $1, $2, $3
echo "$@" #will print the same thing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.