help-bash
[Top][All Lists]
Advanced

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

Re: Is $SHELL used by bash in anyway?


From: Koichi Murase
Subject: Re: Is $SHELL used by bash in anyway?
Date: Fri, 25 Feb 2022 21:33:37 +0900

2022年2月25日(金) 20:35 Jeffrey Walton <noloader@gmail.com>:
> On Fri, Feb 25, 2022 at 5:53 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> > In a script run by corn (on macOS), $SHELL is shown as /bin/sh, $BASH
> > is shown as /bin/bash.
> >
> > Within the script, I run this command. $BASH is changed to
> > "/usr/local/bin/bash", but $SHELL remains as /bin/sh.
> >
> >    LANG=en_US.UTF-8 exec /usr/local/bin/bash -c "source ~/.bashrc;
> > some_other_script.sh"
> >
> > Does bash use the variable $SHELL in any way? Or bash simply leave it
> > as is as a regular environment variable without doing anything extra?

It seems there are only two places in the Bash codebase that touch the
variable SHELL:

https://git.savannah.gnu.org/cgit/bash.git/tree/variables.c?h=devel&id=e7a56619a2f8d8d8e49ba96b9febc22bce1f74f0#n788
https://git.savannah.gnu.org/cgit/bash.git/tree/shell.c?h=devel&id=e7a56619a2f8d8d8e49ba96b9febc22bce1f74f0#n1297

The former initializes SHELL only when it is not defined. The latter
make SHELL readonly for restricted_shell (started by bash -r). The
value of SHELL doesn't seem to be used.

> I believe the first line (shebang) of some_other_script.sh should be:

I feel that is just an example to explain the question.

> /usr/bin/env is Posix and portable. It works nearly everywhere.

The command "env" is POSIX, but AFAIK, the location /usr/bin/env is
not POSIX [e.g. XBD 10.1]. Even the interpretation of shebang is
unspecified in POSIX [XCU 2.1(1)]. I agree that it is the most
portable way and would recommend it for the general case, but it is
unrelated to POSIX.



reply via email to

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