PDA

View Full Version : [SOLVED] Run comands/scripts without "./" at the beginning



UnknownFearNG
March 10th, 2012, 05:34 PM
Probably been asked hundreds of times, but I never know how to fix this. How do I make it so, if I enter a command, preferably from any folder, I can run it without having to put "./" at the beginning?

evilsoup
March 10th, 2012, 05:59 PM
You need to put the file in a directory that is in your $PATH, that is: the list of directories Linux keeps, that it will search for when you type in a command. More info here (http://linuxcommand.org/wss0010.php#path).

The easiest (and best) way to do this is to create a directory at ~/bin. So in a terminal, type

mkdir ~/bin

or you can do this by opening the file manager and create the directory through that. By default, Ubuntu has a line in your .profile that adds this folder to your $PATH if it exists. Note that you'll have to log out and then log in again for this to take effect. Any scripts that you put in this directory will be run just by typing their name, no matter where you are in the filesystem, and they can also be set to keybindings.

If for some reason you need to add a different folder (you almost certainly don't, if you need to store the script in another folder you'd be better off making a symbolic link to that file in your ~/bin), then open up your .profile - in a terminal type

gedit ~/.profile

and then add a line like this:

export PATH=/path/to/directory:$PATH

Cheesemill
March 10th, 2012, 06:49 PM
Having to type ./ when an executable is not in your path is in some ways a security feature.

What would happen if I managed to save a file called ls or sudo (or any other frequently used command name) in your home folder with some nasty code in it and you then tried to use that command.....

AnojiRox
March 10th, 2012, 07:06 PM
just put this into terminal:"bash /path/to/file/here.sh"

UnknownFearNG
March 11th, 2012, 09:51 PM
You need to put the file in a directory that is in your $PATH, that is: the list of directories Linux keeps, that it will search for when you type in a command. More info here (http://linuxcommand.org/wss0010.php#path).


Ah, I remember seeing this link awhile ago. Thanks for reminding me about it and linking it :). This will be great help!



What would happen if I managed to save a file called ls or sudo (or any other frequently used command name) in your home folder with some nasty code in it and you then tried to use that command.....

It would execute the custom script first, which would not be good.