On Tue, Dec 13, 2022, at 6:38 AM, Emanuele Torre wrote:
> On Tue, Dec 13, 2022 at 03:07:16AM -0500, Lawrence Velázquez wrote:
>> Of course not. I only meant to demonstrate that "export" always
>> creates global variables, so a function that utilizes "declare -gx"
>> actually behaves more like "export" then your alias does.
>
> This is a little inaccurate.
>
> `export' doesn't always act on the *global* variable, but "declare -g"
> does.
>
> The differences are that:
> * `declare' (without -g), always acts on variables in the current
> dynamic scope, and will create a new variable in the current dynamic
> scope if no variable with the name it was looking for exists.
>
> * `export' and `readonly' act on the variable they can see, and set
> their "x"/"r" attribute; they will only create a new variable (in the
> global scope) if no variable with the name they were looking for
> exists in any dynamic scope. Just like simple "a=b" assignments.
You're right, thanks for clarifying. I was thinking exclusively
about the behavior when creating variables.
--
vq