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
Programming solutions, source code, solutions to tech problems and other tech related stuff.
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
Thursday, December 16, 2010
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 :)
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 :)
Subscribe to:
Posts (Atom)