参见英文答案 > Meaning of $? (dollar question mark) in shell scripts 8个
我看到代码写在网上的某个地方,我想知道究竟什么是“$?”做/给我们.
谷歌搜索没有帮助.
这是我看到的代码:
#!/bin/sh
ping -c 2 localhost
if [ $? != 0 ] ; then
echo "Couldn't ping localhost, weird"
fi
ping -c 2 veryweirdhostname.noend
if [ $? != 0 ] ; then
echo "Surprise, Couldn't ping a very weird hostname.."
fi
echo "The pid of this process is $$"
摘自:http://efod.se/writings/linuxbook/html/shell-scripts.html
解决方法:
示例C程序(example.c):
int main() { return 1; }
示例Bash:
gcc -o example example.c
./example
echo $? # prints 1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。