Results 1 to 5 of 5

Thread: Run comands/scripts without "./" at the beginning

  1. #1
    Join Date
    Feb 2012
    Location
    Richmond Hill, ON
    Beans
    127
    Distro
    Ubuntu 12.04 Precise Pangolin

    Unhappy Run comands/scripts without "./" at the beginning

    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?

  2. #2
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Run comands/scripts without "./" at the beginning

    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.

    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
    Last edited by evilsoup; March 10th, 2012 at 06:02 PM. Reason: clarity

  3. #3
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Run comands/scripts without "./" at the beginning

    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.....
    Cheesemill

  4. #4
    Join Date
    Feb 2012
    Beans
    21

    Re: Run comands/scripts without "./" at the beginning

    just put this into terminal:"bash /path/to/file/here.sh"

  5. #5
    Join Date
    Feb 2012
    Location
    Richmond Hill, ON
    Beans
    127
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Run comands/scripts without "./" at the beginning

    Quote Originally Posted by evilsoup View Post
    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.
    Ah, I remember seeing this link awhile ago. Thanks for reminding me about it and linking it . This will be great help!

    Quote Originally Posted by Cheesemill View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •