Monday, November 30, 2009

Making a shell script executable

Taken from: http://tldp.org/LDP/abs/html/invoking.html

Let's say you write a script to say "Hello World".

test.sh:
#!/bin/bash
echo "Hello World"
exit 0
You can execute this script by typing:
./test.sh
But you get the following output:
-bash: ./test.sh: Permission denied
you need to grant "execute" & "read" permissions for this script for yourself or for everyone. You can do this by typing: 
chmod o+rx test.sh
(this will give read & execute permissions to "Other" users)
chmod u+rx test.sh
(this will give read & execute permissions to the current "User")
chmod uo+rx test.sh
(this will give read & execute permissions to the current "User" & to "Other" users)

For further reading on mac bash scripting, and a comparison on Perl, Bash, & Applescript:
http://macdevcenter.com/pub/a/mac/2003/11/07/scripting_osx.html?page=3

No comments:

Post a Comment