mm2270 / Casper-API

Casper Suite JSS API scripts and applications
66 stars 10 forks source link

Unexpected token #2

Closed benducklow closed 8 years ago

benducklow commented 8 years ago

Seeing the below errors when trying to run this script against Casper 9.82:

$ sudo sh /Users/me/Documents/My_Scripts/Create-JSS-Computer-Group-Report.sh 
-e Stage 1: Creating directory structure...

-e Stage 2: Obtaining list of all policy IDs...

A total of 38 policies will be accessed...
/Users/me/Documents/My_Scripts/Create-JSS-Computer-Group-Report.sh: line 66: syntax error near unexpected token `<'
/Users/me/Documents/My_Scripts/Create-JSS-Computer-Group-Report.sh: line 66: `done < <(printf '%s\n' "$ALL_POLICY_IDS")'

I've confirmed the script has execution rights. The user account I entered in the script does have full Auditor privileges as well. Thanks.

mm2270 commented 8 years ago

Hi @benducklow ! Wanted to get back to you on this. The reason you're seeing that error is because you're overriding the script's interpreter, aka shebang, by calling it as sh /path/to/script.sh When you do this, it tells Terminal to run the script as a Bourne shell script, but its coded as a Bash script, #!/bin/bash vs #!/bin/sh Some of the syntax used in the script is bash specific, such as the process substitution command. The syntax looks something like this in general:

while read line; do
    echo "$line"
done < <(ls ~/Documents/)

This doesn't work in /bin/sh, but does in /bin/bash. As long as the script is executable, just call it by its path and name in Terminal and it should run, i.e. /path/to/script.sh and it should work.

Try that and post back if there's still an issue, but I'm pretty certain that will solve it for you.

Cheers.

mm2270 commented 8 years ago

Hi @benducklow, just checking in again. Did my post above help solve this for you? I'd like to close this issue if so. Please let me know, thanks.

benducklow commented 8 years ago

Yes, just running the script via the /path/to/script.sh without any prefixes was the trick. Thanks much for the responses (and the script)!

mm2270 commented 8 years ago

Good to hear its working now. Thanks for the reply.