#example8 - to see if it is near the end of the month# set `date` # use backward quotes if [ "$3" -ge 21 ] then echo "It is close enough to the end of the month to proceed" else echo "This report cannot be run until after the 21st of the month" exit $3 fi
在这个例子中,设置了六个变量(通过空格彼此分开):
$1 = Fri $2 = Feb $3 = 6 $4 = 08:56:30 $5 = EST $6 = 2004
#example10 - Do not let the script run over the weekend# set `date` # use backward quotes if [ "$1" = "Sat" -o "$1" = "Sun" ] then echo "This report cannot be run over the weekend."
#example11 - display declining variables, up to three if [ "$#" -gt 3 ] # see if more than three variables are given then echo "You have given more than three variables."
exit fi echo $* if test -n "$2" then shift echo $* fi if test -n "$2" then shift echo $* fi
它将按以下方式执行:
$ example11 one one $
$ example11 one two one two two $
$ example11 one two three one two three two three three $
$ example11 one two three four You have given more than three variables. $