help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Indirect variable assignment with declare


From: noone
Subject: [Help-bash] Indirect variable assignment with declare
Date: Fri, 18 Aug 2017 00:41:50 +0300

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).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]