一.特殊符合
1 | 管道符號
2 >重定向
3 >>重定向
4 2>重定向錯誤輸出
5 >/dev/null 2>&1
6 *匹配任意字符 ?一個字符
7 \ 轉義字符 3\*5
8 ; 命令分隔符
9. “”把內容作爲普通字符輸出 有幾個除外 $ `` ‘’
10 & 後臺進程符
11 && 邏輯與
12 || 邏輯或
13 !邏輯非 排除指定範圍 ls a[!2-4]
14 `` 把他們所包含的內容作爲命令去執行.
二.循環
1. for循環。
For 變量名
In 數值列表(值1,值2,……)(可省略)
Do
語句
Done
2. while循環。
While 命令/條件
Do
語句
Done while條件成功則執行do,否則。。。。
3. if語句
if 命令/條件 若爲真,則執行then後語句
then
語句
Else 語句(改句話可以沒有)
Fi
例: vi 11 內容如下
#!/bin/bash
clear
tput cup 10 40
echo -n "please type in the username:"
tput cup 11 40
read AA
if grep $AA /etc/passwd >/dev/null
then
tput cup 12 40
echo "$AA is a vilid user!"
else
tput cup 12 40
echo "$AA is not a vilid user!"
fi
4. if 命令/條件 若條件成功,則執行1;若不成功,則根據2判斷,
then 成功,則執行2;否則,執行語句3
語句1
Elif 條件/命令2
Then
語句2
Else
語句3
Fi
5. case 語句(多條件判斷) (系統中例子有很多)
case $變量名 in
值1)語句1
;;
值2)語句2
;;
值3)語句3
;;
值4)語句4
;;
Esac
自己寫一個小程序
System manage
************************
1. show the user
2. test the network
3. show the PID
4. kill the process
5. shutdown the system
6. reboot the system
0. exit
************************
Please type in the optin:_
答案:
#!/bin/bash
clear
tput cup 2 28
echo "System Manage"
tput cup 3 24
echo "******************"
tput cup 4 24
echo "1.show the user"
tput cup 5 24
echo "2.test the network"
tput cup 6 24
echo "3.show the PID"
tput cup 7 24
echo "4.kill the process"
tput cup 8 24
echo "5.shutdown the system"
tput cup 9 24
echo "6.reboot the system"
tput cup 10 24
echo "0.exit"
tput cup 11 24
echo "******************"
tput cup 12 24
echo -n "Please type in the option:"
read AA
case $AA in
1)w
;;
2)tput cup 13 24
echo -n "please type in the IP:"
read BB
if ping -c1 $BB >/dev/null 2>&1
then
tput cup 14 24
echo "chenggong"
else
tput cup 14 24
echo "shibai"
fi
;;
3)tput cup 13 24
echo -n "Please type in the terminal ID:"
read CC
ps -t $CC
;;
4)tput cup 13 24
echo -n "please type in the PID:"
read DD
kill -9 $DD
;;
5)init 0
;;
6)init 6
;;
0)exit
;;
*)tput cup 13 24
echo -n "input error,please retry!"
;;
esac
read AAA
shell編程(bash shell)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Linux核心技能与应用
wy53780
2020-04-23 14:02:05
Python與家國天下
豌豆花下貓
2019-02-24 22:22:40
linux上安裝Docker(非常簡單的安裝方法)
幸運券發放
2019-02-24 19:38:01
2019年Java面試-併發容器篇
王知無
2019-02-24 15:12:46
淺淡個人學習嵌入式Linux過程
wx5c317e5b736d2
2019-02-24 13:31:30
DHCP服務原理與搭建(Linux系統+路由器,二選一方案)
wx5c7174443c6f9
2019-02-24 13:23:18
Redis安裝與配置
劉遄
2019-02-24 13:12:51
如果同事暗中傷害你,應該怎麼辦?
這個饅頭有餡
2019-02-24 13:59:08
職場中,抱怨越多的員工,越被領導瞧不起!
這個饅頭有餡
2019-02-24 13:59:08
老程序員被裁,應屆生卻能月薪 1.3 萬?這你能忍?
前端高達
2019-02-24 13:48:04
遇到到處蹭吃卻從不請客吃飯的主怎麼辦?
樑軍年
2019-02-24 13:26:35
Linux基本操作命令
wbzjacky
2019-02-24 13:12:38
高標準機房綜合配線安裝
wbzjacky
2019-02-24 13:12:38