加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 19:03:29 所属栏目:安全 来源:网络整理
导读:Applescript似乎没有正确地逃避字符串.我究竟做错了什么? 例: set abc to "funky-!@#'#"chars"display dialog abcdisplay dialog quoted form of abc 预期/期望的产出: funky-!@#'#"chars'funky-!@#'#"chars' 实际产量: funky-!@#'#"chars'funky-!@#''
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 "atb" --> "bta"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读