Connecting Tech Pros Worldwide Help | Site Map

what does :=0 mean in shell scripting

Member
 
Join Date: Jun 2007
Posts: 48
#1: Oct 8 '08
Hi,

Could anyone please let me know what does it mean by the following statement in solaris shell scripting.

$PROMPT " Select an option: "
read ans
db_option=${ans:=0}

I wanted to know the interpretation for this last line. what does it mean by :=0

Please let me know asap.
Newbie
 
Join Date: Oct 2008
Posts: 6
#2: Oct 8 '08

re: what does :=0 mean in shell scripting


One would think it means 'oh-no!!!'

Truth is, it is a bash shell construct for assigning a default value. In this case, it means 'if they don't give me a value, use zero'.

Google up bash-shell default-value for info, or see here, about 2/3's of the way down the page, for a default values title.

http://www.ibm.com/developerworks/library/l-bash-parameters.html?ca=drs-

The section offers a slightly technical recap that talks about :+, :-, := and :? Luckily, the more technical part is something most users won't need right away -- it gets into substitution timing (before or after using the default), and it also has a snippet of code you can experiment with until you get the hang of the nuances, *if you really need 'em*.

G'luck, mate.
Reply