Ubuntu – Add custom script to PATH

14.04bashcommand lineenvironment-variablesscripts

I know there are quite some answers about that, but still could not make my way around it. I read all this and tried to follow the example under System-wide environment variables (for my case of course), and also tried to do as the chosen answer here. But didn't work.

So, I have an executable shell script, located in ~/Developer/android-studio/bin and I want to make it so that when I am in the terminal (no matter were) and I write simply android-studio and the script to be executed (the IDE to start).

So, I tried with export AS=$PATH:~/Developer/android-studio/bin and also with

AS="~/Developer/android-studio/bin:${PATH}"
export AS

and then source .bashrc, but after both tries, when I write simply AS I get command not found. How can I make this work?

Another question – is it obligatory that I name the variable with capitals only and no dashes, because I want to name the variable something like android_studio instead of AS, i.e.?

Best Answer

It sounds like you want to do

export PATH="$PATH:~/Developer/android-studio/bin"

Then you'll be able to enter android-studio from anywhere. There's nothing magical about an environment variable named AS

If you want a shorthand, add a function to your .bashrc:

function as() { command android-studio "$@"; }
Related Question