$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.com
14 # ORGANIZATION:
15 # CREATED:09/02/2016 21:19
16 # REVISION:---
17 #===========================================================================================
18 TIME_LIMIT=10
19 INTERVAL=1
20
21 echo
22 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 variable
27 if [ "$SECONDS" -eq 1 ]
28 then
29 units=second
30 else
31 units=seconds
32 fi
33
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 $INTERVAL
37 done
38 exit 0
$HOME变量-------------用于引用Bash实例的全路径名。
$IFS变量--------IFS时内部字段分隔符的缩写。此变量决定当Bash解析字符串时将怎样识别字段,或单词分界线。变量$IFS的默认值是空格(空格/制表符/换行),但可以被修改。
1 $ set x y z
2 $ 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 else
11 echo "Exit!"
12 fi
$UID变量------当前用户的账号识别码(ID号),与/etc/passwd中记录的相同,$UID是一个只读变量,不支持修改。
1 root_id=0
2 if [ "$UID" -eq "$root_id" ]
3 then
4 echo "You are root."
5 else
6 echo "You are just an ordinary user."
7 fi
8
9 exit 0