Bash internal variable learning and Bash variable learning

Source: Internet
Author: User

Bash internal variable learning and Bash variable learning

$ SECONDS variable --------- number of SECONDS after the script has been run. Script instance:

 1 #!/bin/bash - 2 #=========================================================================================== 3 # 4 # 5 #                                    FILE:seconds.sh 6 #                                    USAGE:./seconds.sh                               7 #    DESCRIPTION: 8 #     9 #         OPTIONS:---10 #    REQUIREMENTS:---11 #            BUGS:---12 #           NOTES:---13 #          AUTHOR:Yuan Shaoqian(Mark),yuanshaoqiancom@gmail.com14 #    ORGANIZATION:15 #         CREATED:09/02/2016 21:1916 #        REVISION:---17 #===========================================================================================18 TIME_LIMIT=1019 INTERVAL=120 21 echo22 echo "Hit Control-C to exit before $TIME_LIMIT seconds."23 echo 24 25 while [ "$SECONDS" -le "$TIME_LIMIT" ]26 do # $SECONDS is an internal shell variable27 if [ "$SECONDS" -eq 1 ]28 then29   units=second30 else31   units=seconds32 fi33 34 echo "This script has been running $SECONDS $units."35 #On a slow or overburdened machine,the script may skip a count every once in a while.36 sleep $INTERVAL37 done 38 exit 0

The $ HOME variable ----------- is used to reference the full path name of a Bash instance.

$ IFS Variable -------- the abbreviation of the internal field separator when IFS is used. This variable determines how the field or word line is recognized when Bash parses a string. The default value of variable $ IFS is space (space/TAB/line feed), but can be modified.

1 $ set x y z2 $ IFS=“:;-”3 $ echo "$*"4 x:y:z

$ OSTYPE variable ----- operating system type

$ TMOUT variable ------ if $ TMOUT is specified with a non-zero value, this value will be used by the Bash Internal Command read as the default timeout seconds.

 1 set -o nounset 2 TMOUT=3 3  4 echo "Are you sure?(Y/N)" 5 read input 6  7 if [ "$input" == "Y" ] 8 then 9   echo "Continue..."10 else11   echo "Exit!"12 fi 

$ UID variable ------ the account ID (ID) of the current user, which is the same as the one recorded in/etc/passwd. $ UID is a read-only variable and cannot be modified.

1 root_id=02 if [ "$UID" -eq "$root_id" ]3 then4   echo "You are root."5 else6   echo "You are just an ordinary user."7 fi8 9 exit 0

 

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.