Getting error when trying to run a shell script from terminal

i type this into the terminal

sh script /Users/Shared/newscript.sh

and i get

script: /usr/bin/script: cannot execute binary file

i have checked permissions on the script and it all looks good.

here is the script

#!/bin/sh

echo "Cleaning Font Caches..."

rm -f /System/Library/Caches/com.apple.ATS.System*.fcache
rm -f /System/Library/Caches/com.apple.ATSServer.FODB_*System
rm -f /System/Library/Caches/fontTablesAnnex*
rm -rf /Library/Caches/com.apple.ATS/

I was able to get it to run by invoking this at the command line:

chmod 755 ~/bin/Testing

(I titled the script ‘Testing.’) For me, the script ran, but I was denied permission to perform the rm’s, probably since I am not the primary user on this machine.

hi rd,

try this:

set normalCommand to "#!/bin/sh

rm -f /System/Library/Caches/com.apple.ATS.System*.fcache
rm -f /System/Library/Caches/com.apple.ATSServer.FODB_*System
rm -f /System/Library/Caches/fontTablesAnnex*
rm -rf /Library/Caches/com.apple.ATS/"

do shell script "sh -c " & quoted form of normalCommand with administrator privileges

display dialog "Font Caches Cleaned."

don’t know if you need admin privs for this but thought i’d add it in just in case.

sh script /Users/Shared/newscript.sh

means: run the binary command “script” as a shell script, which correctly fails!

“script” (man script) is a programm to protocoll your terminal input and output to a file

to run you script you need

sh /Users/Shared/newscript.sh

or

chmod +x /Users/Shared/newscript.sh
/Users/Shared/newscript.sh

if you want to protocol your script’s input and output (just to show you how to use “script”)

script my-protocol.txt
/Users/Shared/newscript.sh
^D

^D means press Ctrl + D. This will terminate “script”