On 10/13/23 9:18 AM, Vincent Lefevre wrote:
With bash 5.2.15(1)-release under Debian (bash 5.2.15-2+b6 package),
on one of my machines:

$ bash -c 'echo $?'
0

$ bash
vlefevre@cventin:~$ echo $?
0

$ bash ; echo $?
vlefevre@cventin:~$ exit
exit
0

and on another one:

$ bash -c 'echo $?'
0

$ bash
vinc17@zira:~$ echo $?
1

$ bash ; echo $?
vinc17@zira:~$ exit
exit
1

The difference seems to be due to the exit status of the last command
of the .bashrc file. But this is undocumented.

How so? The exit status ($?) is the status of "the last command executed,"
and an interactive non-login shell "reads and executes commands from
~/.bashrc."

Note that on the opposite, for a login shell, e.g. "bash -l", the
exit status of the last command of .bash_logout is ignored for the
exit status of bash. So this is confusing.

Think of it like the EXIT trap. If you run `exit 4', you don't want
~/.bash_logout changing that exit status.


Moreover, for "bash -l /dev/null", when .bash_profile ends with a
non-zero exit status, the behavior contradicts

Commands are executed. They are read and executed from .bash_profile.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/


Reply via email to