Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script what is := for?

Tags:

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} ] 
like image 759
freshWoWer Avatar asked Jun 30 '09 15:06

freshWoWer


2 Answers

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.

like image 57
Andrew Hare Avatar answered Oct 31 '22 22:10

Andrew Hare


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.

like image 34
mipadi Avatar answered Oct 31 '22 22:10

mipadi