${Server?}
${parameter:?word}
Display Error if Null or Unset. If parameter is null or unset,the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell,if it is not interactive,exits. Otherwise,the value of parameter is substituted.
该特定变体检查以确保变量存在(既定义又不为null).如果是这样,它会使用它.如果没有,则输出由字指定的错误消息(如果没有字,则输出适当的错误消息),并终止脚本.
这个和非冒号版本之间的实际区别可以在引用的部分的bash联机帮助页中找到:
When not performing substring expansion,using the forms documented below,
bash
tests for a parameter that is unset or null. Omitting the colon results in a test only for a parameter that is unset.
换句话说,上面的部分可以修改为读取(基本上取出“空”位):
${parameter?word}
Display Error if Unset. If parameter is unset,the value of parameter is substituted.
差异如此说明:
pax> unset xyzzy ; export plugh= pax> echo ${xyzzy:?no} bash: xyzzy: no pax> echo ${plugh:?no} bash: plugh: no pax> echo ${xyzzy?no} bash: xyzzy: no pax> echo ${plugh?no} pax> _
在那里,您可以看到,虽然unset和null变量都会导致错误:?,只有未设置的一个错误?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。