[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sourcing script file from inside a function doesn't work anymore
From: |
Greg Wooledge |
Subject: |
Re: sourcing script file from inside a function doesn't work anymore |
Date: |
Mon, 12 May 2014 09:43:09 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, May 12, 2014 at 03:33:34PM +0200, Geir Hauge wrote:
> Oddly, the quotes seem to matter; changing array='(x)' to array=(x)
> makes it work...
>
> $ f() { source <(printf "declare -a array=(x); declare -p array\n"); }; f
> declare -a array='([0]="x")'
OK, this also happens on my system. In fact this is the first time I've
ever seen array='(...)' instead of array=(...) and I had no idea the
quoted version works outside of a function. It seems like an incredibly
strange syntax; without the explicit "declare -a" it would be initializing
a string variable.
But this doesn't change the fact that the original poster is making a
local variable inside the function, which won't be visible outside it.