分页: 1 / 1

bash中的:=是什么意思?

发表于 : 2009-05-20 9:54
wwangzhihang

代码: 全选

# set temporary file name
: ${TMPDIR:=$TEMPDIR}
: ${TMPDIR:=$TMP}
: ${TMPDIR:=/tmp}
这里面的:和:=分别是什么意思?谢谢。
此段代码想干什么呢?

Re: bash中的:=是什么意思?

发表于 : 2009-05-20 9:59
yaoms
bash(1) 写了: ${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 spe‐
cial parameters may not be assigned to in this way.

Re: bash中的:=是什么意思?

发表于 : 2009-05-20 10:00
yaoms
就是给一个默认值。如果前面的是一个未定义变量,就让他等于后面的那个值。

Re: bash中的:=是什么意思?

发表于 : 2009-05-20 10:10
wwangzhihang
yaoms 写了:
bash(1) 写了: ${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 spe‐
cial parameters may not be assigned to in this way.
谢谢

Re: bash中的:=是什么意思?

发表于 : 2009-05-20 10:21
xiooli
哇,学习了,我一直用${pram:-value}呢,不知道这两个有什么区别?