开发者

What's going on with tr(anslate) here?

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 as forward slashes. To make it slightly easier to understand, the tr com开发者_开发技巧mand 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜