Linux Shell指令碼檔案的判斷、中文符號及其字串入參解析
阿新 • • 發佈:2019-02-17
1、shell指令碼中判斷檔案是否存在 if [ -f "$var" ] then......
2、shell指令碼中判斷字串為空 if [ -z "$str"] then......
3、shell指令碼中判斷字串不為空 if[ "$str"] then.....
4、字串入參的注意事項
將字串當做入參時,要用""引起來。在指令碼中使用字串入參時,有兩種方式(指令碼如下:實現在螢幕指定位置輸出字串的功能)
#!/bin/sh
tput init
row=$1
str=$2 #此處接收字串引數 不必用""
echo $str
len=`expr length "$str"` #此處使用$str引數時,需要用""引起來
colnum=`tput cols`
show_col=`expr /( $colnum - $len /) / 2`
tput sc
tput cup $row $show_col
echo "$str"