[Toybox] Would someone please explain what bash is doing here?

Rob Landley rob at landley.net
Sat May 2 13:01:51 PDT 2020


On 4/25/20 3:19 PM, Chet Ramey wrote:
> On 4/24/20 3:07 PM, Rob Landley wrote:
> 
>>> I tested on Mac OS using bash-5.0 and bash-4.4. I'm not really interested
>>> in testing versions before that.
>>
>>   $ bash --version
>>   GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
>>
>> Devuan ascii 2.0 which is basically debian.
>>
>> *shrug* If it doesn't reproduce for you, it doesn't reproduce. Seems impolite
>> _not_ to mention these things when I hit 'em since you've been so helpful.
> 
> I looked on RHEL7 with bash-5.0.17, since it didn't reproduce with the
> devel version, and I did find a problem that seemingly manifested itself
> only on Linux (<expressive shrug>). It was worth fixing anyway.

Why does  the export flag on $_ toggle?

  $ bash -c 'declare -p _'
  declare -x _="/bin/bash"
  $ bash -c 'ABC=DEF; declare -p _'
  declare -- _=""
  $ bash -c 'echo -n; declare -p _'
  declare -- _="-n"
  $ bash -c 'declare -p _; declare -p _; env | grep ^_='
  declare -x _="/bin/bash"
  declare -- _="_"
  _=/usr/bin/env
  $ bash -c 'unset _; declare -p _'
  declare -- _="_"

It _is_ always exported, and it recreates itself each command. Even after
assignments it's blank rather than unset. But when it first runs, it's exported,
and every time after that it's a local even though the child process gets an "_"
(with a different value).

I'm confused again...

Rob



More information about the Toybox mailing list