How to running command from anywhere in Mac OS (bash scripts)

ruucm
Today I Solved
Published in
1 min readJun 26, 2018

What

I want to make my own bash scripts like this in terminal

start-my-workspace

goes to run below bash scripts

cd /Users/ruucm/Carver/vagrant-local
vagrant up
cd /Users/ruucm/Carver/vagrant-local/www/col-harbor
code .

How

  1. Make ‘bin’ dir in your home directory
mkdir ~/bin

2. Write your scripts in the ‘bin’ directory

vim ~/bin/start-my-workspace

Don’t forget to allow read & write permission that scripts

chmod 777 ~/bin/start-my-workspace

3. Add the folder to your PATH.

vim ~/.bash_profile

add your folder

# Including my scripts
PATH="~/bin:${PATH}"
export PATH

4. Restart the terminal

That’s it !

Then when you type ‘start-my-workspace’, it runs your script from anywhere in your Mac OS 😀

--

--