[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable output
From: |
Greg Wooledge |
Subject: |
Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs |
Date: |
Fri, 19 Oct 2018 15:50:26 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Fri, Oct 19, 2018 at 09:41:41PM +0200, Ricky Tigg wrote:
> Built-in function 'set' produces variable outputs.
> $ export SSLKEYLOGFILE=/home/user/test
>
> $ set | grep SSL
> SSLKEYLOGFILE=/home/user/test
> _=SSLKEYLOGFILE
This is not a bug. The Special Parameter "_" is explained in the manual:
_ At shell startup, set to the absolute pathname used to invoke
the shell or shell script being executed as passed in the envi‐
ronment or argument list. Subsequently, expands to the last
argument to the previous command, after expansion. Also set to
the full pathname used to invoke each command executed and
placed in the environment exported to that command. When check‐
ing mail, this parameter holds the name of the mail file cur‐
rently being checked.
What you're seeing is simply that the varying content of $_ sometimes
matches your grep, and sometimes not.
wooledg:~$ true
wooledg:~$ echo "$_"
true
wooledg:~$ true blue
wooledg:~$ echo "$_"
blue
wooledg:~$ true blue | grep foo
wooledg:~$ echo "$_"
wooledg:~$ X=Y
wooledg:~$ echo "$_"
wooledg:~$ export X=Y
wooledg:~$ echo "$_"
X
In your example, after the export command, $_ contains "SSLKEYLOGFILE"
and therefore it matches your first grep. However, after that grep
command finishes, $_ is empty (I don't know why -- possibly because each
"command" of the pipeline runs in a subshell?), and so it does NOT match
your second grep.
- GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Ricky Tigg, 2018/10/19
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs,
Greg Wooledge <=
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Grisha Levit, 2018/10/19
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Robert Elz, 2018/10/22
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Robert Elz, 2018/10/23
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Bob Proulx, 2018/10/23
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Robert Elz, 2018/10/24
- Re: GNU Bash v.4.4.23-5 built-in function 'set' produces variable outputs, Chet Ramey, 2018/10/24