Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-20-2007, 03:18 PM   #1
LQ Newbie
Registered: Jun 2007
Posts: 7

Rep: Reputation: 0
Adding a Path to .bash_profile

I have an account on a group of servers called ace-net, and there is a program on there (in a very different folder) which I would like to add a path name for. However, I am unsure as the exact command(s) needed to put in the folder.

The path I want to add is /home/pyuet/usr/local/gromacs-3.3.1/bin/<program name>

I've googled it, but several sites say slight different things, so I'm confused.

Below is the only code located in .bash_profile at the moment.

if [ -f /usr/local/lib/bash_profile ]; then
. /usr/local/lib/bash_profile

I appreciate any help that can be given!
Old 06-20-2007, 03:40 PM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
At the end of .bash_profile, add the following:
export PATH=$PATH:/home/pyuet/usr/local/gromacs-3.3.1/bin
If your $HOME is correctly set (and it probably is), you could put this instead:
export PATH=$PATH:$HOME/usr/local/gromacs-3.3.1/bin
From there, you can either source your .bash_profile to make the settings take effect (source .bash_profile or . .bash_profile), log out and log in again, or type the export statement on the command line to have it take effect for just the current shell.
Old 06-20-2007, 04:00 PM   #3
LQ Newbie
Registered: Jun 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you!

However, when I tried to source it, I got the error message if: Expression Syntax.

I tried taking out the path command, and it did the same thing.

What is in there right now is:

if [ -f /usr/local/lib/bash_profile ]; then

export PATH=$PATH:/home/pyuet/usr/local/gromacs-3.3.1/bin

(If you can see them, those little really light blue dots don't mean anything).


Last edited by nexisrocks; 06-20-2007 at 04:01 PM.
Old 06-20-2007, 04:44 PM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
You should enclose code samples in a CODE block to preserve indentation when posting them. The if command syntax looks OK to me. Is bash or sh your default shell?

if [ -f /usr/local/lib/bash_profile ]; then
   .  /usr/local/lib/bash_profile
Bash expects the system startup script to be located in /etc/profile. This location is not standard so it is sourced if it exists. Since you added spaces which look like little dots, I can't tell if the second line is
. /usr/local/lib/bash_profile
or /usr/local/lib/bash_profile
or ./usr/local/lib/bash_profile
The first will source the /usr/local/lib/bash_profile file.
The second will run /usr/local/lib/bash_profile in a subshell, so changes in that script won't be retained.
The third will run $HOME/usr/local/lib/bash_profile. See if this script exists.

export PATH=$PATH:/home/pyuet/usr/local/gromacs-3.3.1/bin
This line will add /home/pyuet/usr/local/gromacs-3.3.1/bin/ to your $PATH variable. This line looks correct if you are using the bash or sh shell.

If you are using another shell, then /home/pyuet/.profile may not be sourced when you login.
Look at the output of "grep pyuet /etc/passwd".
pyuet:x:1000:1001:The Great Mr Pyuet:/home/pyuet:/bin/bash
The last field will contain something like /bin/bash or /bin/sh or /bin/csh or /bin/tsh.
You can change your default shell with the "chsh" command. (see man chsh).
The possible shells are listed in /etc/shells:
cat /etc/shells
Don't select /bin/true or /bin/false of course. /usr/false is used for system user accounts to prevent logins on that account.

One other thing to note. Even if you are using the /bin/bash shell, it is only sourced when you login.

There is another way of doing the test in your ~/.profile script. You can use the test command:
From my ~/.profile:
test -z "$PROFILEREAD" && . /etc/profile

Your three lines could be instead:
test -f /usr/local/lib/bash_profile && . /usr/local/lib/bash_profile

Last edited by jschiwal; 06-20-2007 at 04:49 PM.
Old 06-20-2007, 08:54 PM   #5
LQ Newbie
Registered: Jun 2007
Posts: 7

Original Poster
Rep: Reputation: 0
My default shell is tcsh.

if [ -f /usr/local/lib/bash_profile ]; then

export PATH=$PATH:/home/pyuet/usr/local/gromacs-3.3.1/bin
Is what it is supposed to be (so option number three).

How do I tell if a script exists? Do I use:

echo $HOME/usr/local/lib/bash_profile
If I run that, it returns /home/sfitzsim/usr/local/lib/bash_profile (which I assume means it does exist).

When I try to run "grep pyuet etc/passwd", it says grep can't open etc/passwd.

I still don't understand why it's returning an error on the 'if' - how do I fix it?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I put PATH in bash_profile or bashrc or both? nick623 Linux - General 14 03-31-2007 07:41 PM
Adding Java to my path in the .bash_profile file .... jmax24 Linux - General 5 04-20-2004 02:14 PM
kde3.2 $PATH and .bash_profile easywebdev Slackware 2 03-29-2004 05:42 PM
kshell in path & .bash_profile dmartinez Linux - Newbie 3 03-31-2003 11:15 PM
.bash_profile & path Syncrm Linux - General 11 01-30-2002 02:49 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:31 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration