shell判斷一個文件是否為空 shell腳本怎么判斷變量或參數(shù)是否為空?
shell腳本怎么判斷變量或參數(shù)是否為空?#!/bin/bash # Your Answer # filename: if.sh # chmod x if.sh # ./if.sh 2 4 # 2
shell腳本怎么判斷變量或參數(shù)是否為空?
#!/bin/bash # Your Answer # filename: if.sh # chmod x if.sh # ./if.sh 2 4 # 2 * 4 = 8 # ./if.sh 2 # Please Enter parm2 # ./if.sh # Please Enter parm1 and parm2 # -n 表示變量非空 # ! 取反 即為空 # $1 $2 表示傳遞的第一個第二個參數(shù) if [ ! -n "$1" ] then echo Please Enter parm1 and parm2 exit fi if [ ! -n "$2" ] then echo Please Enter parm2 exit fi echo $1 * $2 = `expr $1 * $2`
shell腳本如何判斷目錄下的多個文件夾是否為空?
隨便寫幾個啦
1. bash-ini-parser
顧名思義,可以解析ini
2. trap f EXIT
在退出前執(zhí)行函數(shù)f,方便的多點退出hook
3. ${str//x/y}
把字符串str里的x都替換成y
4. ${str##*x}
將字符串str的開頭刪掉直到最后一個x的位置
5. if [ -z "$x"] then
判斷變量x是否為空
6. $(cut -d"-" -f2 <<< $x)
把x按照"-"分割,再取第二列
7. comm
8. split
9. ${arr[@]} ${arr[1]}
數(shù)組的使用方法
10. ("a b c")
空格分割的字符串可以通過()轉(zhuǎn)成數(shù)組
11. pushd popd
需要切換目錄的時候,可以保存成棧結(jié)構(gòu)
12. for fn in ./* do
遍歷文件夾中的文件名
怎樣用shell判斷一個文件是否為空文件?
1、if語句判斷-s filename 如果 filename存在不為空,則為真 [ -s /var/log/syslog ] 取反存在且為空[ ! -s /var/log/syslog ]2、例如#!/bin/shfile=~/a.txtif [ ! -s $file ]thenecho $file is a blank fileelseecho $file is not a blank filefi