我看到代码写在网上的某个地方,我想知道究竟什么是"$?" 做/给我们.谷歌搜索没有帮助.
这是我看到的代码:
#!/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 $$"
Run Code Online (Sandbox Code Playgroud)
取自:http://efod.se/writings/linuxbook/html/shell-scripts.html