Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] What the use of .bashrc

Interesting. I had written my own, ages ago, but I made them two
separate functions. Also, they work not only for PATH, but for
any similar environment variable such as MANPATH, CLASSPATH, etc.

I never made them check for a pre-existing instance, though; they were
simple one-liners. Thanks for the tip; I'm updating them to do that.


    prepend-path PATH /path/to/bin
    append-path PATH /path/to/bin

prepend-path() {
        case "$1" in
                eval "$1=$2:\$$1" ;;

append-path() {
        case "$1" in
          	eval "$1=\$$1:$2" ;;

On Tue, Oct 30, 2012 at 10:36 AM, Jerry Feldman <gaf at> wrote:
> On 10/30/2012 10:13 AM, Rich Pieri wrote:
>> On Tue, 30 Oct 2012 07:50:48 -0400
>> Glenn Hoffman <glennhoffman at> wrote:
>>> existence of .bashrc, since I have never used it myself. What's the
>>> reason for a separate startup file for a non-login interactive shell?
>> As a matter of principle, an interactive session should have one and
>> only one login process associated with it. That's the login shell,
>> whether it's BASH or something else.
>> As a matter of practice, logging in on the console is a little
>> different from starting a screen session. Having separate login and
>> non-login run command files makes this easy keep sane. This is just one
>> practical example among many.
> Agreed. In the case of a Gnome or KDE session, it is the session that is
> effectively the login shell. but neither gnome nor kde parse ~/.profile.
> They generally use xinitrc.
> The bottom line is it is, IMHO, best to set your path, environment
> variables and  aliases ~/.bashrc. There is a very nice function in
> /etc/bashrccalled pathmung() that allows you to add path variables to
> your path either at the beginning or end but without duplicating anything:
> pathmunge () {
>     case ":${PATH}:" in
>         *:"$1":*)
>             ;;
>         *)
>             if [ "$2" = "after" ] ; then
>                 PATH=$PATH:$1
>             else
>                 PATH=$1:$PATH
>             fi
>     esac
> }
> If you read the function, it first tests to make sure your element is
> not already in $PATH. In the default case '*)' it looks if you have
> specified, 'after', and if so, it appends the element to your path,
> otherwise it prepends.
> --
> Jerry Feldman <gaf at>
> Boston Linux and Unix
> PGP key id:3BC1EB90
> PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90
> _______________________________________________
> Discuss mailing list
> Discuss at

John Abreau / Executive Director, Boston Linux & Unix
PGP KeyID: 32A492D8 / Email: abreauj at
PGP FP: 7834 AEC2 EFA3 565C A4B6  9BA4 0ACB AD85 32A4 92D8

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /