[vox-tech] checking for interactive shell in bash
Micah Cowan
vox-tech@lists.lugod.org
Thu, 25 Jul 2002 16:04:38 -0700
Peter Jay Salzman writes:
> begin Micah Cowan <micah@cowan.name>
> > Pete, I'm not sure I understand - /etc/profile and all the other bash
> > init scripts (e.g., ~/.bash_profile and ~/.bashrc) are never run under
> > a noninteractive invocation (cf. the man page), unless --login was
> > specified. There should be no need for this test.
>
> that was my understanding, but my system begs to differ.
>
> as a test, i put
>
> echo "blah"
>
> in /etc/profile. i then went to lucifer and scp'd something from
> satan. i saw "blah". you can try it for yourself.
>
> if you have an explanation for why i saw "blah" during scp, i'd be all
> ears! i just assumed the man page was wrong (it happens).
I am almost certain that the man page is correct - because other
programs which invoke noninteractive sessions do not run
/etc/profile. Which leaves one remaining possibility: scp doesn't run
noninteractive shell sessions.
After peeking at the source, it's interesting to note that scp is
absolutely nothing more than a wrapper that calls ssh, which handles
the real work. It seems very likely that ssh has no noninteractive
mode (I can't find one in the man page), so that would certainly cause
this problem.
...I just confirmed this by performing a similar test to the one you
describe above. When I run bash -c, ~/.bashrc is not loaded (and,
presumably, neither are any others). However, when I run ssh with a
command, it gets run. ssh always invokes a login shell, it seems.
It may not necessarily be ssh's fault - it might be something to do
with the PAM modules, if it was compiled with support.
-Micah