• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Bash question

Vadatajs

Diamond Member
At work I recently installed linux on my main workstation (sweet machine, but that's another topic). The shell defined in my NIS password map is /usr/bin/sh, which doesn't exist by default on my distribution. Changing my NIS password map is not an option, I support far too many systems, both HP-UX and Solaris for this to work. What I have done as a workaround is symlinked /bin/bash as /usr/bin/sh to allow me to login to my box. The problem is, when I do this, it does not seem to read ~/.bashrc, so my tab completion is broken, and DIRCOLORS are not set when I list directories.

My question is: why, when I am calling bash from a /usr/bin/sh symlink, do these functions break, yet when I manually call bash, they work? How do I get bash to read .bashrc when I am referring to it as the /usr/bin/sh symlink?
 
There are a couple of possibilities here:
1. .bashrc isn't called on login shells. ~/.bash_profile is. I think.
2. Calling bash by using sh is different than when you run bash. I'm not sure if this would affect you, since you're calling the bash executable, just through a symlink named sh.
 
From 'man bash' (bash 2.05b):

When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.

...

When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.

When bash is started non-interactively, to run a shell script, for
example, it looks for the variable BASH_ENV in the environment, expands
its value if it appears there, and uses the expanded value as the name
of a file to read and execute.
 
Also from 'man bash':

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the
POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and
execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an inter-
active shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to
read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no
effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode
after the startup files are read.
 
Ok, I'm thinking the solution here is to remove the symlink and make /usr/bin/sh the following script:

(hmm, I get errors with this when I try to use the "Attach Code" option)

#!/bin/bash
bash


Is there a better way, so I'm not calling bash twice for every login shell I invoke?
 
Originally posted by: Nothinman
Is there a better way, so I'm not calling bash twice for every login shell I invoke?

Make a bash symlink to sh on all of the other servers and change your NIS shell? =)

LOL, all 800 of them? Ok, I'll get right on that.😉
 
Back
Top