我怎样才能逃避AppleScript的壳论点? [英] How can I escape shell arguments in AppleScript?

查看:151
本文介绍了我怎样才能逃避AppleScript的壳论点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AppleScript的似乎不正确转义字符串。我在做什么错了?

Applescript does not seem to properly escape strings. What am I doing wrong?

例如:

set abc to "funky-!@#'#\"chars"
display dialog abc
display dialog quoted form of abc

预期/所需的输出:

Expected / Desired Output:

funky-!@#'#"chars
'funky-!@#\'#"chars'

实际输出:

funky-!@#'#"chars
'funky-!@#'\''#"chars'

正如你所看到的,看来在实际输出AppleScript的是增加和逃避一个额外的

我将与结束字符为两种 确定,我还要被罚款既单引号和双引号转义 - 但似乎只有单引号实际上逃脱

I would be OK with the end characters being either ' or " and I would also be fine with both the single and double quotes being escaped - but it appears that only the single quotes are actually escaped.

推荐答案

反斜杠不在壳单引号内通常PTED间$ P $。

Backslashes aren't usually interpreted inside single quotes in shells.

在单引号字符放在标志着preserves单引号内的每个字符的字面意义。单引号不能单引号内发生。

Enclosing characters in single quotation marks preserves the literal value of each character within the single quotation marks. A single quotation mark cannot occur within single quotation marks.

一个反斜​​杠不能用于在以单引号设置一个字符串逃脱单引号。嵌入式引号可以通过书面形式创建的,例如:一个'\\''B',这将产生A'B

A backslash cannot be used to escape a single quotation mark in a string that is set in single quotation marks. An embedded quotation mark can be created by writing, for example: 'a'\''b', which yields a'b.

不过他们是通过回声在SH PTED间$ P $,这是由使用的shell做shell脚本

However they are interpreted by echo in sh, which is the shell used by do shell script:

do shell script "echo " & quoted form of "\\t" --> "\t"

取消设置 xpg_echo 使得它表现得像在bash回声:

Unsetting xpg_echo makes it behave like the echo in bash:

do shell script "shopt -u xpg_echo; echo " & quoted form of "\\t" --> "\\t"

通常是简单的使用重定向定界符代替:

Often it's simpler to use HEREDOC redirection instead:

do shell script "rev <<< " & quoted form of "a\\tb" --> "b\\ta"

这篇关于我怎样才能逃避AppleScript的壳论点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆