Customizing bash on AIX

AIX is really different from most distros I am used to. I am trying to set up my .bashrc so I did this in the file. I noticed when I ssh into the server or use the bash command for a new shell it was being ignored.

#-------------------------------------------------------------
# Source global definitions (if any)
#-------------------------------------------------------------


if [ -f /etc/bashrc ]; then
      . /etc/bashrc   # --> Read /etc/bashrc, if present.
fi
# Set Vim as my default editor
export EDITOR=vim

export PATH=$PATH:/opt/nimsoft

echo "Loading /u/user/.bashrc..."

Then I added the first one to my .profile. Is the first one better or the second one better? I have seen both used. When I login with ssh .bashrc seems to be working. Is there a better way to do this? When I use the bash command for a new shell my .bashrc is being ignored. Can I get some recommendations on how to handle this?

if [ -s ~/.bashrc ]; then
    source ~/.bashrc;
fi

if [[ -f ~/.bashrc ]] ; then
	. ~/.bashrc
fi

After figuring this out I would like to push this out to all of our AIX servers. How would I do this without screwing up the ksh users? I prefer bash and ksh is the default shell.

I have the following in my .profile (could be as well .bash_profile).

# to behave like a csh we first read .bashrc
[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc"

I do not source a system /etc/bashrc because I may not do any assumption how it is named or how it is used.
For example, it can be sourced already before my .bashrc, so it is sourced twice (and in extreme cases can misbehave).

First off: AIX is not a "distro" it is its own UNIX, with its own kernel, etc.. This is NOT "some other kind of Linux", it is not Linux at all. Notice that AIX uses a Korn Shell as its native shell. If you want to use bash as a login shell you not only have to install it but also add it to the list of allowed shells in (IIRC - have no AIX system at hand to verify) /etc/security/login.defs

As an AIX administrator for the last 25 years i suggest NOT to use the bash at all - at least not for administration purposes! Subtle differences between ksh and bash might come to bite you and error analysis is difficult enough without adding complexity to the system. By the way, ksh is also the better shell, IMHO, but that is a different topic.

In case i cannot convince you to stay away from bash:

You should NOT put what you wrote in .profile but in .bashrc . First, .profile is executed whenever you log on, not whenever you start a shell. But you want an RC script to be run whenever a shell starts, be it a login shell or a second, third, ... instance, no? Exactly this is done with an rc-script. Most people want a consistent environment whenever they start a new shell.

Furthermore, if you place configuration commands in .profile they would be executed by any login shell. So, if you change the login shell to ksh, it would be fed bash-commands and you probably would not want that either. Put this line:

export ENV=/path/to/shell-configuration-file

into your profile. This tells the login process, which starts our login shell to run exactly this rc-script. It should (for most purposes) be the normal rc-script for your shell, so either (for ksh):

export ENV=~/.kshrc

or (for bash)

export ENV=~/.bashrc

Notice that the file needs to be flagged executable. Here is a little trick, btw.: always set the PATH completely in the rc-script. My setting usually looks like:

export PATH="/usr/bin"
       PATH="$PATH:/usr/local/bin"
       PATH="$PATH:$HOME/bin"
       ....

Most people only add pathes and usually end up with i.e. /usr/local/bin five times in their path. You can avoid that with my method because the first line not only sets the first path but also clears it, so at the end it is always set in the same way, regardless of how many shell instances i open.

I hope this helps.

bakunin