Execute a shell file from anywhere

205 Views Asked by At

I can open my Arduino and Android Studio IDE irrespective of my current path by these commands

 ~/arduino/./arduino 
 ~/android/./studio

I've created aliases for both of them on my .bashrc file and its working fine.

I want to know if there is a more efficient way of solving this kind of problems?

4

There are 4 best solutions below

0
On

You can add folders to your users path variable in the .profile file in your home directory. (or .bash_profile if it exists, since bash will prefer that folder.)

See: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

0
On

You have to update your PATH variable in your .bash_profile:

export PATH="$PATH:$HOME/arduino"

See here for an explanation of the differences between various Shell startup files.

0
On

~ represents you home directory in your system. That is why you can open those programs from anywhere. But, if you login as another user, this won't work as ~ would then represent to that user's home directory.

If you want you can replace ~ by /home/<yourUsername> (the absolute path to your home directory) or even /root depending upon your installation settings.

0
On

the answer given by ceving is good but incomplete, once added to your path, you can execute your file but you should not use the

./
extension. So finally you'll have to do:

 export PATH="/home/arduino:$PATH"

then just call your executable file:

 arduino
 studio