- 论坛徽章:
- 0
|
以下是一个系统当前时间,根据输入的位置变量"$1"加上或减去位置变量"$2"多少分钟的time.pm脚本。
1 #!/bin/bash
2 #time.pm
3
4 if [ "$#" -ne 2 ];then
5 echo "Please input two parameters,such as:[-+]m 0-59"
6 echo -n "Do you again?[y/n] "
7
8 while read CHOICE
9 do
10 case ${CHOICE} in
11 y|Y)
12 echo -n "Please input two parameters,such as:[-+]m 0-59 "
13 read PARM MIN
14 exec /home/xfm/time.pm ${PARM} ${MIN}
15 ;;
16 *)
17 break
18 ;;
19 esac
20 done
21
22 elif [ "$1" = "+m" -o "$1" = "m" ] && [ "$2" -ge 0 -a "$2" -le 59 ];then
23 time_p=$(date -d "+$2 minute")
24 echo ${time_p}
25
26 elif [ "$1" = "-m" ] && [ "$2" -ge 0 -a "$2" -le 59 ];then
27 time_m=$(date -d "-$2 minute")
28 echo ${time_m}
29 else
30 echo "The time's format is wrong"
31 exit
32 fi
终于弄好了。 |
|