Hi everyone,
I'm encountering an issue when running a shell script via JAMF. The script only works if it is written as a one-liner. When I try to run the same script in its normal, multi-line format, JAMF throws errors. Interestingly, if I save the script as a file and execute it, it works perfectly. Additionally, JAMF seems to dislike empty lines in the script and throws errors related to them.
Here is a snippet from my Script which fails:
to_json_array(){
local list=("$1")
local array="["
while IFS= read -r item; do
item=$(printf "%s" "$item" | sed 's/"/\\\\"/g')
array+="\\"$item\\", "
done <<< "$list"
array="${array%, }]"
echo "$array"
}
And that's the error to this:
1:233: execution error: /Library/Application Support/ZuluDesk Scripting/com.zuludesk.scripting.60a1e7ef-234b-11ef-8da8-024f99ac106f/com.zuludesk.scripting.60a1e7ef-234b-11ef-8da8-024f99ac106f.command: line 25: syntax error near unexpected token `{
'
/Library/Application Support/ZuluDesk Scripting/com.zuludesk.scripting.60a1e7ef-234b-11ef-8da8-024f99ac106f/com.zuludesk.scripting.60a1e7ef-234b-11ef-8da8-024f99ac106f.command: line 25: `to_json_array(){
' (2)
Has anyone else encountered similar issues with multi-line scripts in JAMF? Is there a known workaround or best practice to avoid these errors?
Thanks in advance for any insights or suggestions!