Parameter Expansion ${}
shell参数扩展说明
shell 参数扩展格式:
${expression}expression表达式可以为任意的字符,直到匹配到'}'为止,因此表达式包含'}'的话需要用转义或者用单引号包含起来。
值替换
${parameter:-word}
如果parameter为null或者未设置,整个参数替换表达式值为word
${parameter:=word}
如果parameter为null或者未设置,整个参数替换表达式值为word,并且parameter参数值设置为word
${parameter:?word}
如果parameter为null或者未设置,则打印出错误信息。否则,整个参数替换表达式值为$parameter
${parameter:+word}
如果parameter不为null或者未设置,则整个参数替换表达式值为word字符串替换
Examples
字符串长度
Examples
字符过滤
Examples
See also
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
Last updated
Was this helpful?