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

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

问题描述

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

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天全站免登陆