I'm trying to debug an larger osascript 'do shell script' program and have narrowed the problem down to a much shorter repro case that I don't understand at all. Here's the repro case:
osascript -e 'do shell script "echo 123; echo 45; echo 6"'
Gives me the output:
653
Can anybody explain what's going on? It's almost like 'do shell script' does not properly handle line endings, or tries to print everything on one line.
CodePudding user response:
Applescript replaces \n characters with \r characters when reading the output of a shell script. You can tell this is happening by running the output through od -c
:
$ osascript -e 'do shell script "echo 123; echo 45; echo 6"' | od -c
0000000 1 2 3 \r 4 5 \r 6 \n
0000011
To turn this off, use the without altering line endings
parameter.
osascript -e 'do shell script "echo 123; echo 45; echo 6" without altering line endings'
See Technical Note TN2065 for more.