[Top][All Lists]

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

Re: curiosity: 'typeset -xr' vs. 'export -r'

From: Lawrence Velázquez
Subject: Re: curiosity: 'typeset -xr' vs. 'export -r'
Date: Tue, 13 Dec 2022 19:03:58 -0500
User-agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead

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.


reply via email to

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