This little example shows the syntax of how to run some AppleScript/osascript from a Unix shell script on a Mac OS X system:
tell application "Safari"
close window 1
Just put your AppleScript in between the
EOF parts, save it to a file, make the file executable, and this gives you a nice way to run a multiline AppleScript script from a shell script.