| 关键词: nbsp 语句 24echo cup tput 条件 please 命令 System 字符 |
一.特殊符合1 | 管道符号2 >重定向3 >>重定向4 2>重定向错误输出5 >/dev/null 2>&16 *匹配任意字符 ?一个字符7 \ 转义字符 3\*58 ; 命令分隔符9. “”把内容作为普通字符输出 有几个除外 $ `` ‘’ 10 & 后台进程符11 && 逻辑与12 || 逻辑或13 !逻辑非 排除指定范围 ls a[!2-4]14 `` 把他们所包含的内容作为命令去执行.二.循环1. for循环。 For 变量名 In 数值列表(值1,值2,……)(可省略) Do 语句 Done2. while循环。 While 命令/条件 Do 语句 Done while条件成功则执行do,否则。。。。3. if语句 if 命令/条件 若为真,则执行then后语句then语句Else 语句(改句话可以没有)Fi 例: vi 11 内容如下 #!/bin/bashcleartput cup 10 40echo -n "please type in the username:"tput cup 11 40read AAif grep $AA /etc/passwd >/dev/nullthentput cup 12 40echo "$AA is a vilid user!"elsetput cup 12 40echo "$AA is not a vilid user!"fi4. if 命令/条件 若条件成功,则执行1;若不成功,则根据2判断, then 成功,则执行2;否则,执行语句3 语句1 Elif 条件/命令2 Then 语句2 Else 语句3 Fi5. case 语句(多条件判断) (系统中例子有很多) case $变量名 in 值1)语句1 ;; 值2)语句2 ;; 值3)语句3 ;; 值4)语句4 ;; Esac自己写一个小程序System manage************************1. show the user2. test the network3. show the PID4. kill the process5. shutdown the system6. reboot the system0. exit************************Please type in the optin:_答案:#!/bin/bashcleartput cup 2 28echo "System Manage"tput cup 3 24echo "******************"tput cup 4 24echo "1.show the user"tput cup 5 24echo "2.test the network"tput cup 6 24echo "3.show the PID"tput cup 7 24echo "4.kill the process"tput cup 8 24echo "5.shutdown the system"tput cup 9 24echo "6.reboot the system"tput cup 10 24echo "0.exit"tput cup 11 24echo "******************"tput cup 12 24echo -n "Please type in the option:"read AAcase $AA in1)w;;2)tput cup 13 24echo -n "please type in the IP:"read BBif ping -c1 $BB >/dev/null 2>&1thentput cup 14 24echo "chenggong"elsetput cup 14 24echo "shibai"fi;;3)tput cup 13 24echo -n "Please type in the terminal ID:"read CCps -t $CC;;4)tput cup 13 24echo -n "please type in the PID:"read DDkill -9 $DD;;5)init 0;;6)init 6;;0)exit;;*)tput cup 13 24echo -n "input error,please retry!";;esacread AAA 本文出自 “龙哥” 博客,请务必保留此出处http://gehailong.blog.51cto.com/765312/268429 |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|