这里的 tr(anslate) 是怎么回事?
在 applescript 中,如果我这样做:
do shell script "echo \"G:\\CRE\\MV Studios\\Exhibition Projects\"|tr \"\\\\\" \"/\""
我希望所有的反斜杠都会作为正斜杠返回。为了使其更容易理解, tr 命令看起来像这样,没有所有转义
tr "\\" "/" #there's still an escaped \ for the shell
但我得到的是:
"G:/CRE/MV Studiosxhibition Projects"
请注意,当我从脚本编辑器复制它时,它在丢失的 /E 应该在的地方添加了一个奇怪的字符,但它没有不会出现在事件日志中或在我发布此内容后。显然它用 \E 做了一些奇怪的事情。
关于如何处理它有什么想法吗?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来
echo
正在将\E
解释为转义字符(ASCII 代码 27,ESC)。您可以使用echo -E
选项禁用此功能,以禁用转义序列的解释。来自我的 Mac 上的 help echo:
It appears that
echo
is interpreting\E
as an escape character (ASCII code 27, ESC). You can disable this with theecho -E
option to disable interpretation of escape sequences.From help echo on my Mac: