发表文章

[Objective-C] 在 cmd 中转义双引号时打印反斜线 Backslash is printed when escaping double quotes in cmd[shuttle]

franklin88 2017-10-9 62

测试配置:
{
"名称": "测试转义字符",
"cmd": "回声" 你好 ";回音 ' 世界 ';"
}

输出:
回声 "你好";回音 ' 世界 ';
你好"
世界

预期:
回声 "你好";回音 ' 世界 ';
你好
世界

注意:
相同的结果使用 unicode u0022 = > {"cmd": "回声 \ u0022Hello\u0022;回音 ' 世界 ';"}

环境:
MacOS 10.10。5
穿梭 v1.2。7
iTerm2 构建3.0。8
终端. app 2.5.3 (343.7)

原文:

Test configuration:
{
"name": "Test escaping characters",
"cmd": "echo "Hello"; echo 'world'; "
}

Output:
$ echo "Hello"; echo 'world';
"Hello"
world

Expected:
$ echo "Hello"; echo 'world';
Hello
world

Notes:
Same result using unicode \u0022 => {"cmd": "echo \u0022Hello\u0022; echo 'world'; "}

Environment:
MacOS 10.10.5
Shuttle v1.2.7
iTerm2 Build 3.0.8
Terminal.app 2.5.3 (343.7)

相关推荐
最新评论 (16)
thshdw 2017-10-9
1

你想要完成什么?它似乎像预期的那样工作。
如果我手动键入终端 echo \"Hello\" , 我得到的预期输出"Hello"
我得到这个, 因为我逃避双引号, 他们打印。

如果我手动键入终端 echo "Hello" , 我得到的预期输出Hello
我得到这个, 因为我是转义双引号, 所以他们不打印

原文:

What are you wanting to accomplish? It seems that its working as expected.
If I manually type in terminal echo \"Hello\" I get the expected output of "Hello"
I get this because I'm escaping the double quotes and they print.

If I manually type in terminal echo "Hello" I get the expected output of Hello
I get this because I'm Not escaping the double quotes so they don't print

franklin88 2017-10-9
2

也许我还不完全理解逃跑是怎么运作的让我给你一个真实的生活例子。
我要运行以下命令:ps -ef | grep java | awk '{print "Pid: "$2, $8, $9, $10}'

如果我把这个插入航天飞机. json 配置文件我必须转义print部分的双引号, 否则它会中断配置文件, 所以我的 cmd 如下所示:"cmd": "ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'"

但是, 当我通过航天飞机执行它运行它与反斜线打破实际命令:

$ ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'
awk: syntax error at source line 1
 context is
        {print >>>  \ <<< "Pid: \"$2, $8, $9, $10}
awk: illegal statement at source line 1

我做错了什么?

原文:

Probably I'm not fully understanding how escaping works. Let me give you a real life example.
I want to run the following command: ps -ef | grep java | awk '{print "Pid: "$2, $8, $9, $10}'

If I insert this in the shuttle.json config file I have to escape the double quotes of the print part otherwise it breaks the config file, so my cmd looks like this: "cmd": "ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'"

But when I execute this through shuttle it runs it with the backslashes breaking the actual command:

$ ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'
awk: syntax error at source line 1
 context is
        {print >>>  \ <<< "Pid: \"$2, $8, $9, $10}
awk: illegal statement at source line 1

What am I doing wrong?

franklin88 2017-10-9
3

顺便说一下, 如果我应用相同的名称标签, 它的工作原理就像我期望:

名称标记配置如下:
"name": "ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'"

在菜单中显示没有反斜线:

ps-ef |grep java |awk "{打印" Pid: "$ 2, $ 8, $ 9, $ 10}"

原文:

Btw, if I apply the same to the name tag it works like I would expect:

Name tag is configured as follows:
"name": "ps -ef | grep java | awk '{print \"Pid: \"$2, $8, $9, $10}'"

And in the menu it shows up without the backslashes:

ps -ef | grep java | awk '{print "Pid: "$2, $8, $9, $10}'

thshdw 2017-10-9
4

@Franklin88真棒, 谢谢你的真实世界的例子。我会研究一个解决方案。

原文:

@Franklin88 Awesome, Thanks for the real world examples. I'll look into a solution.

thshdw 2017-10-9
5

@Franklin88似乎我们有一个错误的方式双引号逃脱。
我来帮 v1.2。8

原文:

@Franklin88 Seems that we have a bug with the way double quotes are escaped.
I'll have a fix for v1.2.8

franklin88 2017-10-9
6

大!感谢

原文:

Great! Thx

WorldWideWebb 2017-10-9
7

不知道这是否是相同的问题, 但我有一个问题, 想使用反斜线在我的命令, 它不工作。我试着从菜单中运行它, 什么也没有发生 (只要我删除了反斜线, 它就能正常工作)。这是一个在 "移动" 后的权利:

        {
            "name": "Run local site",
            "cmd": "cd /Users/myusername/Library/Mobile\\ Documents/com~apple~CloudDocs/Sites/mysitename && commandhere"
        }

我试过, 没有双反斜线, 也没有工作。

原文:

Not sure if this is the same issue or not, but I'm having an issue with wanting to use a backslash in my command and it not working. I try running it from the menu, and nothing happens (as soon as I remove the backslash, it works fine). It's the one right after "Mobile":

        {
            "name": "Run local site",
            "cmd": "cd /Users/myusername/Library/Mobile\\ Documents/com~apple~CloudDocs/Sites/mysitename && commandhere"
        }

I tried it with and without the double backslash, and neither works.

WorldWideWebb 2017-10-9
8

不知道这是否是相同的问题, 但我有一个问题, 想使用反斜线在我的命令, 它不工作。我试着从菜单中运行它, 什么也没有发生 (只要我删除了反斜线, 它就能正常工作)。这是一个在 "移动" 后的权利:

        {
            "name": "Run local site",
            "cmd": "cd /Users/myusername/Library/Mobile\\ Documents/com~apple~CloudDocs/Sites/mysitename && commandhere"
        }

我试过, 没有双反斜线, 也没有工作。

原文:

Not sure if this is the same issue or not, but I'm having an issue with wanting to use a backslash in my command and it not working. I try running it from the menu, and nothing happens (as soon as I remove the backslash, it works fine). It's the one right after "Mobile":

        {
            "name": "Run local site",
            "cmd": "cd /Users/myusername/Library/Mobile\\ Documents/com~apple~CloudDocs/Sites/mysitename && commandhere"
        }

I tried it with and without the double backslash, and neither works.

thshdw 2017-10-9
9

@WorldWideWebb我已经确认 bug 也导致了这个问题。我会尽量让1.2.8 周末。

原文:

@WorldWideWebb I have confirmed that the bug is causing this issue as well. I'll try to have 1.2.8 for the weekend.

WorldWideWebb 2017-10-9
10

这个 bug 有什么新的吗?

原文:

Anything new on this bug?

thshdw 2017-10-9
11

我的开发系统已经解决了在我发布之前做一些测试。如果你想测试, 我可以把我的东西给你。当前在Gitter上, 如果您想在那里聊天。

原文:

It's resolved on my dev system. Doing some more testing before I release. I can send you what I have if you want to test. Currently on Gitter if you want to chat there.

thshdw 2017-10-9
12

应固定在 v1.2.8。让我知道, 如果它不为你工作。

原文:

Should be fixed in v1.2.8. Let me know if its not working for you.

WorldWideWebb 2017-10-9
13

工作很棒!谢谢!

原文:

Works great! Thanks!

thshdw 2017-10-9
14

@WorldWideWebb感谢您的更新!

原文:

@WorldWideWebb Thanks for the update!

franklin88 2017-10-9
15

你好!谢谢你的新版本越狱的工作现在好多了。但是, 当分析了穿梭. json 文件时, 我仍然遇到一些问题。
在某些情况下, 当串联命令失败时转义分号。例如:

让我们说, 我想打开谷歌和关闭终端后, (只是作为一个例子):

配置:
{
"cmd": "打开https://www.google.es;退出 ",
"inTerminal": "新",
"名称": "谷歌"
}

输出:
打开https://www.google.es \;退出
文件/用户/foobar/退出不存在。

正如可以看到一个反斜线在分号之前, 打破了命令。作为好奇心, 如果我把一个空格前的分号, 它的工作预期:

"cmd": "打开https://www.google.es ;退出"

但是, 我知道它应该在没有空间的情况下工作, 就像从命令行一样。

原文:

Hi! Thanks for the new release. The escaping works much better now. However I'm still experiencing some problems when the shuttle.json file is parsed.
In some cases escaping the semicolon when concatenating commands fails. For example:

Let's say I want to open Google and close the terminal after that (just as an example):

Configuration:
{
"cmd": "open https://www.google.es; exit",
"inTerminal": "new",
"name": "Google"
}

Output:
open https://www.google.es\; exit
The file /Users/foobar/exit does not exist.

As can be seen a backslash is printed before the semicolon which breaks the command. As curiosity, if I put a space before the semicolon it works as expected:

"cmd": "open https://www.google.es ; exit"

However, I understand that it should work with and without a space like it does from the command line.

thshdw 2017-10-9
16

@Franklin88
我会调查这个... 但是您不应该需要 open 指令 try 命令:

"cmd": "https://www.google.es"

这应该在默认浏览器中打开。

原文:

@Franklin88
I'll look into this... however you should not need the open directive try command:

"cmd": "https://www.google.es"

this should open in the default browser.

返回
发表文章
franklin88
文章数
1
评论数
4
注册排名
60671