View Full Version : set path?
hesee
December 27th, 2004, 07:12 AM
I'm beginning programming c with gcc, compilation went presumably ok, but cannot run compiled file a.out:
bash: a.out: command not found
I think i must set path to find the file, but how? I tried:
PATH=$PATH:/home/hesee/C-prog
but after that: echo $path gives only empty line... Anyone who can help?
haha
December 27th, 2004, 11:39 AM
you can run a.out in your home dir by "./a.out". ^^
like this :
$ ./a.out
lordan
December 30th, 2004, 05:32 PM
To answer you question about the path, echo $path will not show you anything (in bash) you need to type echo $PATH. In zsh, echo $path will show you your path (space separated). Remember, shell variables are case sensitive.
You should not get into the habit of doing this, but if you want the current directory to be included in the command search path, you need to do PATH=.:$PATH, since the dot denotes the current directory.
Usually a better idea is to prepend the name of the executable with ./, as haha suggested, or to move the file into a location that is used to hold executable files, such as /usr/local/bin or ~/bin (provided you have it in your search path).
hesee
January 1st, 2005, 11:35 AM
Thanks for advices, I'll be doing as you suggested from now on!
markusfarkus
November 30th, 2007, 10:09 AM
Once you have set a path is there a way to remove it from your path?
komputes
December 20th, 2007, 07:21 AM
Markus, if you used the "PATH=<your_path_here>:$PATH" it will only stay there for the duration that the terminal window stays open. Open a new terminal window and the $PATH variable will be reset to NULL.
I think you can add a PATH from your home directory (in the shell)
gedit /home/markusfarkus/.profile
(besides .profile you can also edit .bashrc or .bash_profile, although I chose .profile, because the path line to my home/me/bin (in the script written as ~/bin) was already in there, so I just appended a directory to it for my personal compilations).
The file will look like this
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
I think it should be there if you need to delete or add any.
If you add any paths separate them by a : colon.
EXAMPLE:
PATH=~/bin:"${PATH}"
becomes
PATH=~/bin:/dir1/dir2/cprogs:"${PATH}"
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.