4 ms·
> 'interactive' is when called with -i flag (which sshd does when reached by > ssh with no command passed, i.e if you do 'ssh ls' it should not call > bashr
by drothlis 14y ago
> 'interactive' is when called with -i flag (which sshd does when reached by
> ssh with no command passed, i.e if you do 'ssh ls' it should not call
> bashrc, but should call bash_profile)
Do you mean that an interactive shell should load .bash_profile? Because the
bash man page says: "When an interactive shell that is not a login shell is
started, bash reads and executes commands from ~/.bashrc".
Re. ssh, the bash man page says (at least on my system, with bash 4.2.37):
"Bash attempts to determine when it is being run with its standard input
connected to a network connection, as when executed by the remote shell daemon,
usually rshd, or the secure shell daemon sshd. If bash determines it is being
run in this fashion, it reads and executes commands from ~/.bashrc".
That last quote from the bash man page contradict my own experiments. Logging
into my OS X system with ssh loads .profile, not .bashrc. The same is true
logging into my Fedora 17 system with ssh. Perhaps sshd uses --login instead
of -i (or, on my systems, happens to be configured in that way).
Running a command via ssh ("ssh hostname somecommand") loads nothing when the
remote system is OS X, and loads .bashrc when the remote system is Fedora 17.
All in all, I will respectfully disagree that "there is no madness". Normally
I completely relate to the RTFM sentiment, and I have spent plenty of time in
the bash manual myself.
I remain unconvinced that there is a better solution than putting everything
into .bashrc (with the $- guard around stuff specific to interactive shells)
and doing nothing in .profile other than unconditionally sourcing .bashrc.
> [[ $- == *i* ]]
Thanks for the sane test syntax: It's much clearer than my ugly mess of almost
every symbol character I could find. :-)
- lloeki 14y ago> Do you mean that an interactive shell should load .bash_profile? No, ssh logs you in, so it is a login shell (and thus calls {bash_,z}profile), but if you call 'ssh ls', it is not an interactive shell since you just ask ssh to launch the 'ls' command remotely. > Logging into my OS X system with ssh loads .profile sshd starts login(1) (which shows the 'Last login:' line), which calls your shell as login
- drothlis 14y agoAh, I understand now: The sentence I quoted from the bash man page refers to ssh only when run with a command ("ssh hostname command"). Thanks!