Bash Shell 变量赋值的一些固定格式

来源:互联网 发布:weka分类算法 编辑:程序博客网 时间:2024/06/03 21:52

变量赋值方式

str 没有赋值

str 为空字符串

str 为非空字符串

备注

var=${str-expr}var=exprvar=$strvar进行设置var=${str+expr}var=$strvar=exprvar进行设置,varstr要不都取值,要不都不取值。虽然取值不同var=${str=expr}str=expr
var=expr
str 不变
var=$str
varstr进行设置,

 

var str保持一致

var=${str?expr}expr 输出至 stderrvar=strvar进行设置var=${str:-expr}var=exprvar=$str var=${str:+expr}var=var=expr var=${str:=expr}str=expr
var=expr
str 不变
var=$str
 var=${str:?expr}expr 输出至 stderr