At my school's Linux cluster, its possible to run executables without the ./ prefix. However, on my home machines, I have to do this.

I tried adding the code folder to the PATH via

export PATH=/home/jason/Code/:$PATH

This worked when I wanted to have some custom scripts available for autocomplete, but the compiled executables aren't showing up.

How can I set up my home machines to execute without the ./ prefix?

  • 1
    I'm assuming you chmod +x already and the name of the binary is not a shorter version of another binary Nov 6 '11 at 23:56
  • You're correct in that assumption. All executables have different names from existing binaries and have executable permissions set
    – Jason
    Nov 7 '11 at 0:10

Try this command instead:

export PATH=$PATH:.

This will make it so that the system will look for executables in current directory without a "./". The command that you gave will make it so that the system will always look in that directory no matter what directory that you are in.

  • 2
    It is probably also worth noting that including . in $PATH is generally considered a bad idea from a security point of view. The current directory is potentially insecure since it could be owned by some other non-privileged user. With the default path settings, it has to be a conscious choice to execute something in the current directory. Nov 7 '11 at 7:50

For your home machine you can just add a bin folder to your home dir., after a restart it will automatically be added to your path with any the recent ubuntu releases. Then you can call your script just with the scriptname

Usually best to make sure that your scriptnames are unique as by default ~/bin will trump /usr/bin. If in doubt just add a # to the end of name. Ex. - find1

No need to have any .sh in scriptnames, note this also works with executable binaires

  • I like this approach. The bin directory could also be a simple link to your ~/Code directory like you do with /usr/src/linux when compiling some modules for different kernel header versions. Nov 7 '11 at 4:12
  • A restart is a bit overkill. It should suffice to log out and back in after ~/bin has been created. The reason for this is that the default ~/.profile you get on Ubuntu checks if ~/bin exists, and if it does it adds it to PATH. And ~/.profile is read when you log in.
    – geirha
    Nov 9 '11 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.