使用sh写一些小型的脚本会使工作更加简单。有部分内容可能大家都比較陌生(至少我是这样)。
就是变量有关的參数展开,以下就是一些简单的描写叙述和使用方法。能够使代码更加简洁
展开运算符
替换运算
${varname:-word} var exist & not null,return value ,else return word
${varname:=word} var exist & not null,return value, else varname=word & return $varname
${varname:?message} var exist & not null,return value, else show message & if not define exit
#test variable is or not exist
${varname:+word} if exist & not null ,return word, else return null
(:)is optional
匹配运算
${variable#pattern}
${variable##pattern}
${variable%pattern}
${variable%%pattern}
# % is from left or right