noone
2017-08-17 21:41:50 UTC
I wonder if the behavior demonstrated below is legit or is it a bug?
arg='--src'
a='abc def'
declare src=$a
echo "src=[$src]" # src=[abc def]
declare src="$a"
echo "src=[$src]" # src=[abc def]
declare ${arg#--}=$a # <------ indirect assignment, no quotes
echo "src=[$src]" # src=[abc] <------ $a got expanded in declare above
declare ${arg#--}="$a"
echo "src=[$src]" # src=[abc def]
Output:
src=[abc def]
src=[abc def]
src=[abc]
src=[abc def]
So the only case declare required quotes on the right side of the
assignment is indirect assignment without quotes.
Does it work as supposed?
My bash version is 4.4.12 (= bash:latest from dockerhub).
arg='--src'
a='abc def'
declare src=$a
echo "src=[$src]" # src=[abc def]
declare src="$a"
echo "src=[$src]" # src=[abc def]
declare ${arg#--}=$a # <------ indirect assignment, no quotes
echo "src=[$src]" # src=[abc] <------ $a got expanded in declare above
declare ${arg#--}="$a"
echo "src=[$src]" # src=[abc def]
Output:
src=[abc def]
src=[abc def]
src=[abc]
src=[abc def]
So the only case declare required quotes on the right side of the
assignment is indirect assignment without quotes.
Does it work as supposed?
My bash version is 4.4.12 (= bash:latest from dockerhub).