On Sun, Dec 11, 2022, at 9:37 PM, L A Walsh wrote:
> I suppose one could create an alias (despite advice that
> functions are "better" -- in this case a function doesn't work).
> I'm using ':;' for PS1, so cut/paste works:
>
>   PS1=':; '
>
> :; Export () {
> :;   typeset -x "$@"
> :; }
> :; Export -r foo_xr=1
>
> :; typeset -p foo_xr
> -bash: typeset: foo_xr: not found

This happens because "declare"/"typeset" creates local variables
within functions.  Using -g works around this...

        $ Export() { declare -gx "$@"; }
        $ Export -r foo=1
        $ declare -p foo
        declare -rx foo="1"

...but now "Export" always creates global variables, rather than
scoping as "declare" and your alias-based version does.  On the
other hand, "export" also creates global variables, so in a sense
the workaround version is more consistent.

        $ f() { export "$@"; }
        $ f var=1
        $ declare -p var
        declare -x var="1"

-- 
vq

Reply via email to