您的位置:首页 > 运维架构 > Shell

Shell parameter expansion

2014-07-12 02:23 218 查看
使用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell linux parameter