$是什么? $ 0 $ 1 $ 2在shell脚本中意味着什么? [英] What do $? $0 $1 $2 mean in shell script?

查看:236
本文介绍了$是什么? $ 0 $ 1 $ 2在shell脚本中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在shell脚本编写中我经常遇到$? $0 $1 $2 etc....,我知道的是$?返回最后一条命令的退出状态

I often come across $? $0 $1 $2 etc.... in shell scripting, what I know is that $? returns the exit status of the last command

echo "this will return 0"
echo $?

但是其他人做什么?他们叫什么,还有更多吗?也许像$ 3 $ 4 $ 5 ...

but what do the others do? what are they called and is there more? perhaps like $3 $4 $5 ...

推荐答案

这些是脚本的位置参数.

These are positional arguments of the script.

执行

./script.sh Hello World

会制造

$0 = ./script.sh
$1 = Hello
$2 = World

注意

如果执行./script.sh,则$0将给出输出./script.sh,但是如果您用bash script.sh执行,它将给出输出script.sh.

If you execute ./script.sh, $0 will give output ./script.sh but if you execute it with bash script.sh it will give output script.sh.

这篇关于$是什么? $ 0 $ 1 $ 2在shell脚本中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆