views:

98

answers:

1

in applescript if i do:

do shell script "echo \"G:\\CRE\\MV Studios\\Exhibition Projects\"|tr \"\\\\\" \"/\""

I'd expect all my backslashes to come back forward slashes. To make it slightly easier to understand he tr command would look like this without all the escapes

tr "\\" "/" #there's still an escaped \ for the shell

But what I get is:

"G:/CRE/MV Studiosxhibition Projects"

Note that when I copied that from Script Editor it added a weird character where the missing /E should be, it doesn't show up in the event log or once I've posted this. Obviously it's doing something weird with \E.

Any ideas on what to do about it?

+4  A: 

It appears that echo is interpreting \E as an escape character (ASCII code 27, ESC). You can disable this with the echo -E option to disable interpretation of escape sequences.

From help echo on my Mac:

echo: echo [-neE] [arg ...]
Output the ARGs. If -n is specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped characters is turned on:

    \a      alert (bell)
    \b      backspace
    \c      suppress trailing newline
    \E      escape character
    \f      form feed
    \n      new line
    \r      carriage return
    \t      horizontal tab
    \v      vertical tab
    \\      backslash
    \0nnn   the character whose ASCII code is NNN (octal).  NNN can be
            0 to 3 octal digits

You can explicitly turn off the interpretation of the above characters with the -E option.

John Kugelman
Similar to my answer but you give a solution, so +1.
paxdiablo
Weird. It works inthe terminal, but do shell script "echo -E \\E"results in "-E "so the option is getting echo-ed as well. -E \
stib
Still not working in Snow Leper. When I look at the echo manpage the only option it lists is -n.
stib
Ah! In bash `echo` is a shell built-in which overrides the `/bin/echo` binary. I changed my default shell from tcsh to bash. In tcsh there is no `-E` option. What happens if you run the command manually in a terminal? I ran `echo "G:\CRE\MV Studios\Exhibition Projects" | tr "\\" "/"` in a tcsh shell and it worked fine, no problem with the `\E`.
John Kugelman