Operating System - HP-UX
1834925 Members
2695 Online
110071 Solutions
New Discussion

Re: How to show the different between :- and :=

 
SOLVED
Go to solution
tikual
Advisor

How to show the different between :- and :=

I know that both of these are used for assigning a default value to the variable. But how can I show the different?

Thanks
3 REPLIES 3
Mark Grant
Honored Contributor

Re: How to show the different between :- and :=

newvalue=${variable:-hello} means newvalue will be set to $variable if $variable already has a value. Otherwise newvalue will be set to "hello"

newvalue=${variable:=hello} means newvalue will be set to "hello" and so will $variable if $variable is not set otherwise newvalue will be set to $variable.

Never preceed any demonstration with anything more predictive than "watch this"
Dietmar Konermann
Honored Contributor
Solution

Re: How to show the different between :- and :=

$ unset bla
$ echo ${bla:-huhu}
huhu
$ echo $bla
sh: bla: Parameter not set.
$ echo ${bla:=huhu}
huhu
$ echo $bla
huhu

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
tikual
Advisor

Re: How to show the different between :- and :=

My wants is Dietmar's answer. Anyway, thanks all of your help!