I have Sage (math program) and I want to execute it through terminal.

I know I can go to the directory and execute it with -

open Sage.app

But would I really want to do is simply type sage in terminal and have it run. I believe this is a fairly simple task, but I just don't have any idea! Thanks.


You need an alias. Typing alias sage='open /PATH/TO/Sage.app' will create an alias which will do exactly what you want, run the program just by typing sage. The problem is that this will only last until you close that terminal window (bash). So, you need to create that alias each time you run a new bash. To do so, just:

  1. Create or modify a text file called .bash_profile in your home directory.
  2. Add alias sage='open /PATH/TO/Sage.app' on it
  3. Save the file
  4. Load the file once by typing . ~/.bash_profile

Remember that it will be case sensitive, so if you type Sage (instead of sage) it won't work.


You need to create a shell script named sage containing:

open /Applications/Sage.app

I suggest creating a bin directory in your home folder, and storing any scripts you create there. Save the script there with the name sage, then execute chmod u+x sage to give your user permission to execute the script.

Now, the last step is to tell bash that it should include any scripts found in ~/bin in your path. To do this edit ~/.bash_profile. You can do nano ~/.bash_profile or use any text editor you like. Add this to the file:

# Prepend ~/bin to the PATH variable
export PATH="$HOME/bin:$PATH"

Save and close .bash_profile, restart bash, and you should be able launch Sage.app by typing sage.

EDIT: An alias, like the other answer said, is probably a cleaner approach (1 less file to keep track of) if you don't need the logic of a script and just want to launch the app.

I've gotten used to doing it this way as most often I find myself passing a lot of parameters that don't change to an executable, but 1 or 2 that might. So I write the script to accept just those parameters and insert them in the right places when calling the executable. Just something to keep in mind.

  • Please try to avoid recommending the creation of new folders within the user's home directory, many people might want to keep a clean sorted home folder, and would prefer other solutions, like just using /bin (for example) – Alexander - Reinstate Monica Jul 7 '12 at 20:25
  • @XAleXOwnZX - creating a new folder under home is much cleaner than writing to /bin - If you use command line binarieies and scripts you need a directory that you can write to without affecting other users – user151019 Jul 7 '12 at 22:40
  • 2
    /bin is a great place for scripts meant for all users or the system in general, but user-specific scripts should really reside somewhere within the home directory. Creating a ~/bin folder makes them much easier to manage and backup. Also, I think it's too much of an assumption to assume that the OP has privileges to write to /bin or /usr/bin. – Vickash Jul 7 '12 at 23:08
  • at least make a hidden folder >_> – Alexander - Reinstate Monica Jul 7 '12 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .