0

Hi everybody,


I decided to ask it here because i didn't know how to ask it on google, i want to know what does this line do:

: ${dummy_msg:="Nothing started."}

Thanks.

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by modesto916
0

There ought to be a space between : and the $.
Anyways, what it does it checks for the existence of a variable called dummy_msg. If it does not exist (not defined) or is empty, it will set the value of the same as 'Nothing started'.

Consider this:

nilesh@Linux ~ $ set | grep dummy
nilesh@Linux ~ $ : ${dummy_msg:="Nothing started."}
nilesh@Linux ~ $ set | grep dummy
dummy_msg='Nothing started.'
nilesh@Linux ~ $ dummy_msg=
nilesh@Linux ~ $ set | grep dummy
dummy_msg=
nilesh@Linux ~ $ : ${dummy_msg:="Nothing started."}
nilesh@Linux ~ $ set | grep dummy
dummy_msg='Nothing started.'
0

ok man, thanks.

But, couldn't i do the same thing just using ${dummy_msg:="Nothing started."}?

Thanks.

0

You can, but it will complain something like command not found.
Because bash will first check for value of dummy_msg. If empty/unset, set the default value given, and try to execute a command with that name.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.