I want to do this in bash:
read -r -d '' script <<'EOF'
echo 1
echo 2
echo 3
EOF
osascript -e "do shell script \"$script\" with administrator privileges"
# Output: 3
# Expected: 1
# 2
# 3
Only the last line is executed.
However, if I do just:
osascript -e "\"$script\""
# Output: echo 1
# echo 2
# echo 3
# Expected: echo 1
# echo 2
# echo 3
You can see all the lines are there.
How do I fix this?
Just add
without altering line endings(though this will add a trailing newline character).