这样一个bash变量的含义是什么?
${Server?}
它的工作原理与(从bash手册页)几乎相同:
原文链接:https://www.f2er.com/bash/386433.html
${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> _