0

I am learning shell scripting and came across this line

: ${CONTAINER_CLI:="docker"}

can someone please explain me what this line do? what is the meaning of : here?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Alankrit010
  • 129
  • 1
  • 3

1 Answers1

0

man bash command said:

${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.

So, the variable CONTAINER_CLI is assigned with the value docker if CONTAINER_CLI does not exists or empty.

But... if you simply write :

${CONTAINER_CLI:="docker"}

You obtain an error if the result is not a command. You just want make a assignation. Put simply a : before.

It's like:

CONTAINER_CLI=${CONTAINER_CLI:="docker"}
Arnaud Valmary
  • 2,039
  • 9
  • 14