General
cancel
Showing results for 
Search instead for 
Did you mean: 

What does a symbol ":" mean in ksh?

SOLVED
Go to solution
Vita
Occasional Contributor

What does a symbol ":" mean in ksh?

Hi,

I've found the following in some old ksh scripts :
1. :> $ERRORS
2. : ${name:="UNKNOWN"}

What does the string's first ":" mean?
I can't find it searching the Internet somehow.

Thanks,
Vita
4 REPLIES
Matti_Kurkela
Honored Contributor
Solution

Re: What does a symbol ":" mean in ksh?

It is a null command, that does not do anything but causes its arguments to be expanded.

In other words, in your example 1.), the file named in the $ERRORS variable is going to be truncated to zero size (or created if it does not exist yet). This could be written without the ":", but apparently the script writer wanted to be explicit.

Your example 2.) sets the variable $name to value "UNKNOWN" if it is not previously set to some non-empty value. This requires the ":" in the beginning: otherwise the shell would attempt to run the command indicated by the $name variable (or if it was empty, it would try to run "UNKNOWN").

MK
MK
Vita
Occasional Contributor

Re: What does a symbol ":" mean in ksh?

Thank you, Matti!
I guess it's a really rare usage of the command...

Vita
Dennis Handly
Acclaimed Contributor

Re: What does a symbol ":" mean in ksh?

You can also use ":" if you are missing a then and you have an else:
if [ 0 -eq 0 ]; then
: do nothing # a comment won't work here
else
echo "this is false"
fi
Vita
Occasional Contributor

Re: What does a symbol ":" mean in ksh?

I have found a solution to this question in the gurus' answers.
Thanks!