作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在查看 bash 脚本中的以下行:
: ${ROOT_DIR:="."}
我相信我理解第二部分是将 ROOT_DIR 变量设置为当前工作目录的扩展。但是,我不确定 ROOT_DIR 是一个特殊的环境变量还是一个普通的环境变量。
此外,前导“:”冒号的具体作用是什么?
最佳答案
ROOT_DIR
并不特殊,它只是这个 shell 脚本碰巧使用的一个变量。:
什么都不做。特别是,它在这里用作虚拟命令以允许 :=
的副作用生效,将默认值分配给 ROOT_DIR
。您可以从 bash 手册页获得更多详细信息:
: [arguments]
No effect; the command does nothing beyond expanding arguments and
performing any specified redirections. A zero exit code is returned.
“扩展参数”是这里的重要部分,它允许默认赋值发生。
${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.
Positional parameters and special parameters may not be assigned to in this way.
关于bash - : ${ROOT_DIR: ="."} do in a bash script? 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17689930/
我是一名优秀的程序员,十分优秀!