Use of colon in this shell script

Hi the following lines appear in a bash shell script.  I would like to know what these lines is doing, the colon in particular.

: ${pidfile:=/bin/lcl_scripts/}
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gmanpertAuthor Commented:
Actually, here is the whole code snippet.

: ${pidfile:=/bin/lcl_scripts/}
 sudo kill -TERM $pid
 case $? in
  1)  echo -n "(not running)";;
  0)  # wait until the processes are gone (the parent is the last one)
  echo -n "(waiting for all children to terminate) "
  for ((wait=0; wait<120; wait++)); do
   if test -f $pidfile; then                       # -f test for regular file
      usleep 50000
   if ! test -f /proc/$pid/exe; then
   if test "$(readlink /proc/$pid/exe 2>/dev/null)" = $apache_bin; then
       usleep 50000


The first colon on the line prevents the rest of the line being interpreted as a command. For example:


Gives an error, because it first assigns "Hello" to v1, then tries to execute the value of v1 as a command.

The "${pidfile:= ... }" means that the value of pidfile is only changed if it is not null or already set. So:

    : ${v1="World!"}
    echo $v1

Produces "Hello", not "World!". This means that pidfile may already have been set on entry to the script, but if it isn't, the script uses the default value.

The second line assigns the contents of pidfile to pid. pidfile is the name of a file containing a process id, "<" reads from that file, so pid ends up set to the contents of the file (the process id).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.