bug-bash
[Top][All Lists]
Advanced

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

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


From: Robert Elz
Subject: Re: curiosity: 'typeset -xr' vs. 'export -r'
Date: Mon, 12 Dec 2022 12:28:19 +0700

    Date:        Sun, 11 Dec 2022 18:37:02 -0800
    From:        L A Walsh <bash@tlinx.org>
    Message-ID:  <639693CE.3060906@tlinx.org>

  | This seems to be an unnecessary "make-wrong", no?  I.e.
  | would it cause some syntactic or semantic problem in bash,
  | if it were allowed?

Not for me to say, but I doubt it.  But it would be one more
needless difference with very little benefit.  And next you'd
want readonly -x as yet another way to do the same thing.

  | I suppose one could create an alias (despite advice that
  | functions are "better" -- in this case a function doesn't work).

They do, when used properly.

  | :; Export () {
  | :;   typeset -x "$@"
  | :; }
  | :; Export -r foo_xr=1
  |
  | :; typeset -p foo_xr
  | -bash: typeset: foo_xr: not found

That's because typeset (declare) in a function makes local
variables, even when you don't ask it to.  I think that's
a poor design (inherited from ksh, which had a non-shell-like
design paradigm, more aiming to be a programming language).

But bash has -g which instructs typeset/declare to make global
instead of local vars.  Add that and the function form works as
you intended.   And then if you want, the function can be extended
to do more,  which the alias cannot.

kre



reply via email to

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