I am using an AIX 5.3 server with a .bashrc file set up to echo "Executing bashrc." When I log in to the server using ssh and run:
bash -c ls
I get:
Executing bashrc
.
..
etc....
However, when I log in with telnet as the same user and run the same command I get:
.
..
etc....
Clearly in the telnet case, the .bashrc was not invoked. As near as I can tell this is the correct behaviour given that the shell is non-interactive in both cases (it is invoked with -c
). However, the ssh case seems to be invoking the shell as interactive. It does not appear to be invoking the .profile, so it is not creating a login shell. I cannot see anything obviously different between the environments in the two cases.
What could be causing the difference in bash behaviour?
Best Answer
Check to make sure that the login shell you're in doesn't have an alias or a different
PATH
depending on whether you're logged in viassh
ortelnet
. Compare this each way:There could be some conditional code in one of:
/etc/profile
/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
That sets the
PATH
differently or creates an alias depending on whether you're logged in viassh
ortelnet
. ThePATH
could point to different versions of Bash that are compiled with different options. An alias could be something likealias bash='bash -i'
.If you
echo $SHELL
as Nikolaidis suggests, that's only going to show what's set in/etc/passwd
as your login shell. It might be more reliable to useps
. If for some reason you're getting a shell other than Bash, you'll need to check its startup files and environment to see if thePATH
or aliases are different. Generally, though, your interactive shell shouldn't affect how explicitly callingbash -c
works.And you're correct about this: