macos – 如何在AppleScript中转义shell参数?

前端之家收集整理的这篇文章主要介绍了macos – 如何在AppleScript中转义shell参数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Applescript似乎没有正确地逃避字符串.我究竟做错了什么?

例:

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

预期/期望的产出:

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

实际产量:

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

正如您所看到的,似乎在实际输出中Applescript正在添加并转发额外的’

我会很好,结尾字符是“或”,我也可以将单引号和双引号转义 – 但看起来只有单引号实际上是转义的.

反斜杠通常不会在shell中的单引号内解释.

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.

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.

然而,它们由echo in sh解释,这是do shell脚本使用的shell:

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

取消设置xpg_echo使其行为类似于bash中的echo:

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

通常使用HEREDOC重定向更简单:

do shell script "rev <<< " & quoted form of "a\\tb" --> "b\\ta"
原文链接:https://www.f2er.com/bash/387181.html

猜你在找的Bash相关文章