@Lauri Ranta's do shell script
pointers are helpful, but a simple variation of the original command does the trick:
Even though do shell script
invokes bash
as sh
and therefore in a mode it calls 'POSIX mode', many bash-specific features are still available, among them the so called here-string to feed a string directly to a command via stdin, e.g.: cat <<<'Print this'
:
Thus, by using a here-string - passed with quoted form of
from AppleScript, which is always advisable - the echo
problem is bypassed:
# Sample input.
set input to "a\\\\b" # equivalent of" 'a\\b'
# Remove all `\` characters; returns 'ab'
set input to (do shell script "sed 's/\\\\//g' <<<" & quoted form of input)
Alternative, using tr -d
instead of sed
:
set input to (do shell script "tr -d '\\\\' <<<" & quoted form of input)