LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to make ./ not necessary when executing (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-not-necessary-when-executing-734200/)

geo_diver 06-19-2009 10:19 AM

how to make ./ not necessary when executing
 
hi, when i want to execute a file in the terminal it always makes me type ./ first, is there something i can edit to have it so i don't have to type ./?

pwc101 06-19-2009 10:23 AM

You can add the current directory to the PATH variable. In ~/.bashrc (or ~/.bash_profile)
Code:

PATH=$PATH:.
export PATH

Some people might advise against having the current directory in your PATH if you're root.

Uncle_Theodore 06-19-2009 10:25 AM

Yes, you just have to include . (the current directory) in the PATH variable. Some distros put . in the PATH for the ordinary users, but never for root.

In ~/.bashrc file, try putting something like this

PATH=$PATH:.

johnsfine 06-19-2009 10:26 AM

Depending on what shell, terminal, desktop, distribution, etc. you are using, there are a bunch of different places you might add or change an export of the PATH variable.

The most likely (not knowing any the details of your system) is ~/.bashrc

Edit that file. Did it already exist? Did it already include a line starting
export PATH=
If so, you can add .: right after the =
If the line wasn't there, you could add
export PATH=.:$PATH

Quote:

Originally Posted by Uncle_Theodore (Post 3579708)
PATH=$PATH:.

I only partially understand the behavior you get by defining PATH without exporting it. I don't think it is the desired behavior.

Adding . at the end of PATH rather than the beginning means it would find programs in . only if the same program is not elsewhere in the path. Again, I think that is not the desired behavior (though I understand why some people might want that behavior).

saivin 06-19-2009 10:32 AM

The files we edit may probably differ from distro to distro. But, I learnt that all environment variables go into .bash_profile and aliases etc go into .bashrc. So, the PATH variable is preferably put in .bash_profile.

Secondly, if I'm right '.' is not necessary to indicate current directory. Just ending the PATH with ':' should do. As,
Code:

echo 'PATH=$PATH:' >> .bash_profile
. .bash_profile

The second line is to restart bash_profile.

geo_diver 06-19-2009 10:47 AM

thanks everybody,
after trying all those suggestions, it appeared to only work in the bashrc file, though i do have a profile file too. but all the different methods worked and i can now compute worry free. but please, do tell, what is a distro?

Uncle_Theodore 06-19-2009 10:52 AM

Quote:

Originally Posted by johnsfine (Post 3579712)
I only partially understand the behavior you get by defining PATH without exporting it. I don't think it is the desired behavior.

Adding . at the end of PATH rather than the beginning means it would find programs in . only if the same program is not elsewhere in the path. Again, I think that is not the desired behavior (though I understand why some people might want that behavior).

Yeah, you're right, I forgot to put "export" before the definition.
As to the other thing, I'd rather have the dot at the end of PATH. Precisely for the reason you've stated. The command is looked up in the current directory only if it's not found elsewhere. Somehow it seems right for security reasons and also prevents certain mess when a program compiled by the user accidentally has the name used in the system.

Uncle_Theodore 06-19-2009 10:54 AM

Quote:

Originally Posted by geo_diver (Post 3579741)
thanks everybody,
after trying all those suggestions, it appeared to only work in the bashrc file, though i do have a profile file too. but all the different methods worked and i can now compute worry free. but please, do tell, what is a distro?

"Distro" is a slang form of "distribution". :) Like Ubuntu, Gentoo, Slackware, Fedora etc.

John VV 06-19-2009 01:52 PM

now if the command you are wanting to run is
configure , make , make install
DO NOT put that folder path into the system path !!!!

But if it is a program that you installed , say Gimp ( i build and install it in it's own folder) then DO put it in the system path

brianL 06-19-2009 01:58 PM

Is it really too much trouble typing ./ before a command?


All times are GMT -5. The time now is 07:37 PM.