What does the following bash snippet do exactly? ${2:-${1}}
“使用第二个参数,但如果没有,那么第一个参数”。
${var:-default}
evaluates to the value of $var
, unless $var
isn't set in which case it evaluates to the text "default"
. $1
, $2
, et al are the command-line arguments to your program (or function). Putting the two together it means to return $2
if there were two arguments passed, otherwise return $1
.
It means "Use the second argument if the first is undefined or empty, else use the first". The form "${2-${1}}" (no ':') means "Use the second if the first is not defined (but if the first is defined as empty, use it)".
如果定义,它会给出$ {2}的值,或者默认为$ {1} http://jaduks.livejournal.com/7934.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.