Assign single variable to an array (in place)
Consider following code:
a=(1 2 3)
a='seven'
export a
declare -p a
The output (from declare) is:
declare -ax a='([0]="seven" [1]="2" [2]="3")'
So a is an array. Questions:
How to change second line, so a will not be an array anymore, but a simple
variable with the value seven? I'm looking for a one-liner, without unset
etc.
Assigning an variable to the array replaces only first element, not the
whole array. Where is this behaviour specified?
(I've answered this question today, which got me thinking on this problem,
and I'm looking for a cleaner solution).
No comments:
Post a Comment