Equivalent of batch file in bash


I use Heroku for Node JS development. When I need to commit and push something to my Heroku server, I run three commands:

git add .
git commit -m "message"
git push heroku master

When I was developing locally, I put the 3 commands into a batch file called ‘aa.bat’. When I needed to commit and push, I would just run the ‘aa’ command instead of typing out 3 lines.

Now that I have moved development to Cloud 9, the batch command doesn’t work. Is there a way to do it?


You could run the following script in the terminal to create aa command

echo '#!/bin/bash
git add .
git commit -m "message"
git push heroku master
' > aa
chmod +x aa
sudo mv aa /usr/local/bin/


sudo rm /usr/local/bin/aa

to remove it


That worked but now I want to improve it. Is there a way to make the “message” a variable. i.e. I want to run it like this:
aa "custom message"
or even better
aa custom message


This should do the trick. To get command line arguments with shell scripts its $1 $2 and so on. And getting the number of arguments is $#


if (( $# < 1 )); then
    echo "Must enter a message"

git add .
git commit -m $1
git push heroku master

And of course:
chmod 755 scriptName.sh
./aa.sh <- To run it

Better solution:
cd ~
mkdir scripts && cd scripts
nano aa.sh
Type the script above
sudo ln -s /usr/local/bin/aa ~/scripts/aa.sh
aa “my awesome message” <- to run it

And you can edit it anytime inside the scripts folder and because its a shortcut you don’t have to do any extra work.


That works. Thank you again.