By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

what does :=0 mean in shell scripting

P: 56
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.
Oct 8 '08 #1
Share this Question
Share on Google+
1 Reply


P: 6
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.
Oct 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.