help-bash
[Top][All Lists]
Advanced

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

Re: Effect of prefixed assignments on built-ins


From: Emanuele Torre
Subject: Re: Effect of prefixed assignments on built-ins
Date: Mon, 1 Jul 2024 01:53:07 +0200
User-agent: Mutt/2.2.13 (00d56288) (2024-03-09)

On Sun, Jun 30, 2024 at 07:18:13PM +0200, Jens Schmidt wrote:
> Hello list,
> 
> I always get baffled about the following difference in behavior:
> 
>   [~]$ echo $BASH_VERSION
>   5.2.15(1)-release
> 
>   [~]$ IFS=foo read a b c <<< "afbocoo"
>   [~]$ echo "<$a:$b:$c>"
>   <a:b:coo>
> 
>   [~]$ IFS=foo export | grep IFS
>   <no result>
> 
> Both "read" and "export" are built-ins, but the prefixed assignment
> "IFS=foo" affects only "read".
> 
> Why?
> 
> Special case or general rule?  If the latter, which?
> 
> I couldn't find anything in the man page explaining that.  I also have
> tried searching the net, but the search terms I tried are all a bit too
> general to give helpful results.
> 
> Please CC me when replying.
> 
> Thanks!
> 

Yeah, weird, it seems  declare -p  export -p  and similar commands that
print out all the variables ignore temporary variables when generating
their print outs:

    $ foo=baz
    $ foo=bar export -p | grep foo=
    $ foo=bar declare -p | grep foo=
    declare -- foo="baz"

Using eval makes them work as expected

    $ foo=baz
    $ foo=bar eval export -p | grep foo=
    declare -x foo="bar"
    $ foo=bar eval declare -p | grep foo=
    declare -x foo="bar"

I don't think that is intended; it only happens when using  declare -p
without a specified variable, it does not happen if you use
declare -p foo :

    $ foo=baz
    $ foo=bar declare -p foo | grep foo=
    declare -x foo="bar"

o/
 emanuele6



reply via email to

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