shell
在shell腳本中,如果用戶不輸入東西,系統不自動退出,this is a bug!
文件測試語句:-d -f -r -w -x -e
邏輯測試語句:“&&”與(同時滿足) “||”或(前為假,后面才實施) “!”非(看中間是與還是或來決定)
整數值比較語句:eq(是否等於) gt(是否大於) lt(是否小於) ge(是否大於或等於) le(是否小於或等於) ne(是否不等於)
字符串比較語句:=(等於) !=(不等於) -z(是否為空)
if條件測試語句
if條件語句的單分支結構有if\then\fi 關鍵詞組成,相當於口語的“如果...那么...”
#vi if.sh
#!/bin/bash
yt="/1/2/3/4"
if[ ! -e $yt] if [ -w $yt]
then
mkdir -p $yt chmod g+w $yt
fi #bash if.sh
#ll if.sh #ll -d /1/2/3/4
#bash if.sh
if條件語句的雙分支結構由if、then、else、fi類似於口語“如果...那么...或者...那么...”
#vi if.sh
('DD'刪除)
#!/bin/bash
ping -c 3 -i 0.2 -w 3 $1 &>/dev/null
if[$? -eq 0]
then
echo"Host $1 is On-line."
else
echo"Host $1 is off-line."
fi
#chmod 777 if.sh
#./if.sh 192.168.26. ...
#! /bin/bash
read -p "please set directory: " n
if [ ! -e $n ]
then
mkdir -p $n
else
echo "this $n directory exist"
fi
#. /if.sh
xx
#ls
. /if.sh
#vi if.sh
#. /if.sh
70
80
90
#vi if.sh
#!/bin/bash
read -p "Enter your parameter : " n
if [ -e $n ] && [ -d $n ]
then
echo "this $n is directory"
elif [ -e $n ] && [ -f $n ]
then
echo "this $n is file "
else
echo "you enter is emputy"
fi
#./if.sh
for條件循環語句
語序一次性讀取多個信息,然后逐一處理
#vi forlist.txt
a
b
c
#vi passwd.sh
#!/bin/bash
read -p "Enter The Users Password:" n
for u in ‘cat forlist’
..............
#ll forlist
#chmod 777 forlist
#chmod 777 passwd.sh
#ls
#./passwd.sh
#chmod 777 passwd.sh
#ll passwd.sh
#./passwd.sh
#vi ipaddr
3個ip地址
#vi foriplist.sh
#bash foriplist.sh
#chmod 777 forcheck.sh