freshWoWer
freshWoWer

Reputation: 64199

Bash script what is := for?

Does anyone know what is := for?

I tried googling but it seems google filters all symbol?

I know the below is something like checking if the variable HOME is a directory and then something is not equal to empty string.

  if [ "${HOME:=}" != "" ] && [ -d ${HOME} ]

Upvotes: 37

Views: 31531

Answers (2)

Andrew Hare
Andrew Hare

Reputation: 351476

From Bash Reference Manual:

${parameter:=word}

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.

Basically it will assign the value of word to parameter if and only if parameter is unset or null.

Upvotes: 62

mipadi
mipadi

Reputation: 410602

From the Bash man page:

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.

Man pages are a wonderful thing. man bash will tell you almost everything you want to know about Bash.

Upvotes: 2

Related Questions