Bash內部變數學習,Bash變數學習

來源:互聯網
上載者:User

Bash內部變數學習,Bash變數學習

$SECONDS變數---------指令碼已經啟動並執行秒數,指令碼執行個體:

 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

$HOME變數-------------用於引用Bash執行個體的全路徑名。

$IFS變數--------IFS時內部欄位分隔符號的縮寫。此變數決定當Bash解析字串時將怎樣識別欄位,或單詞分界線。變數$IFS的預設值是空格(空格/定位字元/換行),但可以被修改。

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

$OSTYPE變數-----作業系統的類型

$TMOUT變數------如果$TMOUT被指定了一個非零的值,此值會被Bash的內部命令read作為預設的逾時秒數。

 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變數------目前使用者的帳號識別碼(ID號),與/etc/passwd中記錄的相同,$UID是一個唯讀變數,不支援修改。

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.