Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

Thursday, December 16, 2010

Example for loop using bash script on Mac

Be careful when doing this... Note that ALL SPACES MUST BE EXACT. Or else bash will cry:


#!/bin/bash
a=1
while [ $a -le 10 ]
do
echo "Loop number $a"
a=$(( $a + 1 ))
done

Shell scripting for Mac (using bash)

An easy example using vi:


1. Type 'vi myscript' into the terminal.

2. Press 'i' for insert, and type your file. For example:

#!/bin/bash
echo "This is my script. Woo"

3. Press 'esc' key to exit insert mode.

4. Press shift+ZZ to save the file and exit.

5. Change the access rights on your file so it can be executed. For example:

chmod -x myscript

6. Execute your script by typing:

./myscript


That should get you started :)