shell-Process State variables

Source: Internet
Author: User

$? 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.