From “learning the bash shell” I find the following:
“${varname:=word} If varname exist and isn't null, return its value; otherwise set it to word and then return its value” p. 91
Code:
So I write the following script:
#
# seeking to understand :=
#
# string [arg1]
#
arg1=$1
arg1=${arg1:="not given"}
echo $1
When I run like so, I get:
But when I run it like this:
The echo prints a blank instead of behaving this way:
I don't understand this as the book claims it will set it to word and then return its value. I thought at first that perhaps it was defaulting back to the actions of :- , but this is found not to be so for when I write the script this way:
Code:
#
# seeking to understand :=
#
# string [arg1]
#
arg1=$1{1:=“not given”}
and run it, it shows an error of incorrect assignment, as is expected if it is functioning correctly (can not set value of positional parameter). So what am I not understanding – that is, why does not the out put look like this:
?????????????????