我是bash的新手.当阅读别人写的bash脚本时,我遇到了这一行.我无法理解其中使用的运算符的含义.
read -p "Enter user domain [subdomain.domain.org] : " USERDOMAIN
USERDOMAIN=${USERDOMAIN:-subdomain.domain.org]
Run Code Online (Sandbox Code Playgroud)
我在bash终端执行此操作,USERDOMAIN的值保持与用户输入的值相同.
你能解释第2行正在做什么吗?
我引述man bash:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion
of word is substituted. Otherwise, the value of parameter is
substituted.
Run Code Online (Sandbox Code Playgroud)
相比之下:
${parameter:=word}
Assign Default Values. If parameter is unset or null, the expansion
of word is assigned to parameter. The value of parameter is then
substituted.
Run Code Online (Sandbox Code Playgroud)