Duck
Duck

Reputation: 35933

Automator AppleScript - trying to echo a string variable to Bash

I am trying to create a service using Automator.

Inside a Run AppleScript action I have a variable that is a string in which each line is a word separated by linefeed. Like this:

à
às
a
ante
ao
aos
após
aquela

When I try to echo this to terminal by doing:

do shell script "echo " & (finalText as string)

I get this error:

The action “Run AppleScript” encountered an error: “sh: line 1: a: command not found
sh: line 2: à: command not found
sh: line 3: ante: command not found
...
sh: -c: line 30: syntax error near unexpected token `do'
sh: -c: line 30: `do'”

Any ideas?

Upvotes: 1

Views: 670

Answers (1)

user3439894
user3439894

Reputation: 7555

To get rid of the command not found type errors in this case, and just about anytime when passing a variable to a do shell script command, use:

do shell script "echo " & finalText's quoted form

You can also use:

do shell script "echo " & quoted form of finalText

Whichever you prefer as appropriate.

Upvotes: 1

Related Questions