[solved] Bad return value upon login ?

If none of the more specific forums is the right place to ask

[solved] Bad return value upon login ?

Postby DoubleHP » 2019-02-11 16:33


I have modified my bashrc to add to my prompt the return value of last command. This works fine on most machines, but one.

Upon login, most machines report 0 (true). But one machine reports false. Login process is fine; but inside the tasget host, the prompt reports 1 just at login time.

After digging, I have to this:

Code: Select all
# head /etc/profile
echo 4
return 5

And during login:

Code: Select all
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Feb 11 18:15:26 2019 from 2a01:e35:xx
-bash-4.4# echo $?
-bash-4.4# echo $?

As you see, I was expecting 5, but got 1. How to dig deeper than profile ? who loads profile ? What represents $? on the very first execution of prompt ? Is there a way to force $? to 0 ? for example, ending bashrc with true did not help.
Last edited by DoubleHP on 2019-02-11 20:16, edited 2 times in total.
Posts: 30
Joined: 2016-10-09 08:55

Re: Bed return value upon login ?

Postby bw123 » 2019-02-11 16:54

...but login hasn't exited, so there wouldn't be a value yet? Probably the return/exit code from the last command preceding login...?

Strange issue, not sure where I'd look. Probably syslog, or the journal? Could it be motd? lastlog? just guessing. Anything executed in a startup like ~.bashrc might be another guess.

too busy to look it up...
User avatar
Posts: 3757
Joined: 2011-05-09 06:02
Location: TN_USA

Re: Bed return value upon login ?

Postby DoubleHP » 2019-02-11 17:12

So, when logging via ssh, what is run before the bash shell ? And what's the parent ?

I have found that the parent of bash is sshd (user cession).

Is it sshd which prints motd and reads password to know which shell to execute ?
Posts: 30
Joined: 2016-10-09 08:55

Re: Bed return value upon login ?

Postby Head_on_a_Stick » 2019-02-11 19:02

Not sure about ssh but check the FILES section of the bash man page, Debian uses ~/.profile instead of ~/.bash_profile though.

Reserved exit codes are listed here: https://www.tldp.org/LDP/abs/html/exitcodes.html
"The trouble with the world is that the stupid are cocksure and the intelligent full of doubt." — Bertrand Russell
User avatar
Posts: 8842
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Bad return value upon login ?

Postby DoubleHP » 2019-02-11 20:16

You are just right.

~/.bashrc was ending with "mesg n", and adding a new line with "true" fixed my issue.

For some reason, this command produces various return values on various machines.

Issue fixed for me. Thanks.

Machines where "mesg n" returns 0 :

Code: Select all
# mesg --help
Usage: mesg [y|n]

Where it returns 1:
Code: Select all
# mesg -V
mesg from util-linux 2.29.2
Posts: 30
Joined: 2016-10-09 08:55

Return to General Questions

Who is online

Users browsing this forum: No registered users and 7 guests