$? is used to determine whether the previous command has performed successfully.
If the return is 0, the execution succeeds and fails if it returns to a different value.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8C/0E/wKiom1hgr87jWK1YAAEsAjWMsos974.png-wh_500x0-wm_3 -wmp_4-s_94414853.png "title=" 1.png "alt=" Wkiom1hgr87jwk1yaaesajwmsos974.png-wh_50 "/>
[Email protected] ~]# Zhouziqi
Bash:zhouziqi:command not found
[[email protected] ~]# echo $?
127
[Email protected] ~]#
$$ is the process number that gets the current shell. In general, when we have a new script, we have to kill the old script, we can get the process number of the current shell script through $$, for example:
[email protected] ~]# cat 1.sh
echo "$$" >/root/a.log
While True
Do
Uptime
Sleep 2
Done
[Email protected] ~]# vim a.
A.log a.sh
[Email protected] ~]# vim A.log
[[Email protected] ~]# sh 1.sh &
[1] 24492
[Email protected] ~]# 14:07:40 up 9:31, 2 users, Load average:0.00, 0.00, 0.00
14:07:42 up 9:31, 2 users , Load average:0.00, 0.00, 0.00
Look at the A.log file to see the process number of this script so we can kill the process.
[email protected] zhouyu]# cat 58.sh
#!/bin/bash
Tar zcf service.tar.gz * >&/dev/null
[$?-eq 0] && Echo OK
The above meaning is to create a tar file, the output of the file to the garbage bin, and then determine whether the above command is successful, if successful output OK
This article is from "Love Zhou Yu" blog, please be sure to keep this source http://izhouyu.blog.51cto.com/10318932/1886420
shell-Process State variables