Re: jerked around by bash

From: Bit Twister (BitTwister_at_mouse-potato.com)
Date: 04/13/05


Date: Wed, 13 Apr 2005 12:38:50 -0500

On Wed, 13 Apr 2005 11:38:28 -0500, craig wrote:
> Something I can never get straight is extending the path/PATH in bash
                                                       path env search_tag

Depends on which shell. Try doing a
              man $(basename $SHELL)
or
              man `basename $SHELL`

For bash, global for everyone
        /etc/profile - environment variables (PATH, USER, LOGNAME,...)
        /etc/bashrc - contains function & aliases, not environment vars

You can place functions in the profile if you want to export the
function name. Example export -f function_name_here.

It is instructive to read the files in /etc/profile.d, if you have one.

I would place site/custom global environment variables in zz_local.sh
That way you can pop zz_local.sh in on new installs.

If you have an /etc/profile.d directory; do a

cd /etc/profile.d
touch zz_local.sh
chmod 755 zz_local.sh
Then add your changes, Example: export PATH=$PATH:new_path:another_path

The zz_local.sh name was picked to force it to be executed last.
/etc/profile runs the scripts in /etc/profile.d
do a ls -1 /etc/profile.d to see order of file execution.

User only
        ~userid_here/.bash_profile - for environment variables
        ~userid_here/.bashrc - for function & aliases, not env vars

ALWAYS do a su -l user_id to test your changes before logging out.

You can place functions in the .bash_profile if you want to export the
function name. Example export -f function_name_here.

Profiles usually run once, bashrc run everytime you spin up a non-login
interactive session.

Sessions inherit env vars from the parent process.

Setting BASH_ENV=~/.bashrc will cause it to execute during
non-interactive session.

Other places environment variables are set are
/etc/X11/xinit.d/
/usr/share/config/kdm/Xsession
/usr/share/config/kdm/kdmrc
/etc/X11/Xsession

If you do not want to follow the code, you can put echo commands in
the top and bottom of each of the command files used during login to
see what is changed where.

Click up two terminals, one for root and one for your user account (rseku)

When you login using the bash shell, the first file to run is
/etc/profile and the other files are /etc/bashrc, ~/.bash_profile and
~/.bashrc.

The first echo in /etc/profile, only, has to be different than all the others.
One angle bracket instead of two angle brackets.

So, at line 2 in /etc/profile
    echo /etc/profile $(umask) $PWD > /tmp/aa
at the bottom of /etc/profile
    echo /etc/profile $(umask) $PWD >> /tmp/aa

in /etc/bashrc line 2
    echo /etc/bashrc $(umask) $PWD >> /tmp/aa
at the bottom of /etc/bashrc
    echo /etc/bashrc $(umask) $PWD >> /tmp/aa

Do the above 2 echo lines for for ~/.bash_profile and ~/.bashrc for
both accounts.

After you make the changes you test by doing a
      su -l rseku
      cat /tmp/aa
      exit
then
      su -l the_other_account
      cat /tmp/aa
      exit

That way if you dink up anything you can exit the rseku login and fix
your typeo as root.

as you look through the login scripts and have code questions you can
look up the command at
http://www.tldp.org/LDP/abs/html/index.html



Relevant Pages