Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslash is printed when escaping double quotes in cmd #194

Closed
Franklin88 opened this issue Sep 12, 2016 · 15 comments
Closed

Backslash is printed when escaping double quotes in cmd #194

Franklin88 opened this issue Sep 12, 2016 · 15 comments
Labels

Comments

@Franklin88
Copy link

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)

@Franklin88 Franklin88 changed the title Backslash is parsed when escaping double quotes in cmd Backslash is printed when escaping double quotes in cmd Sep 13, 2016
@thshdw
Copy link
Collaborator

thshdw commented Sep 13, 2016

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
Copy link
Author

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
Copy link
Author

Franklin88 commented Sep 13, 2016

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
Copy link
Collaborator

thshdw commented Sep 13, 2016

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

@thshdw
Copy link
Collaborator

thshdw commented Sep 14, 2016

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

@thshdw thshdw added the bug label Sep 14, 2016
@Franklin88
Copy link
Author

Great! Thx

@WorldWideWebb
Copy link

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
Copy link
Collaborator

thshdw commented Sep 29, 2016

@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
Copy link

Anything new on this bug?

@thshdw
Copy link
Collaborator

thshdw commented Oct 18, 2016

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 pushed a commit to thshdw/shuttle that referenced this issue Oct 18, 2016
Menus have been translated to Spanish

Added a bash script to the default JSON file that allows writing a
command to terminal without execution fitztrev#200

Fixed an issue that prevented character escapes fitztrev#194

Fixed an issue that prevented tabs from opening in terminal on macOS
fitztrev#198

Fixed an issue where english was not the default language.
@thshdw thshdw mentioned this issue Oct 18, 2016
@thshdw
Copy link
Collaborator

thshdw commented Oct 18, 2016

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

@thshdw thshdw closed this as completed Oct 18, 2016
@WorldWideWebb
Copy link

Works great! Thanks!

@thshdw
Copy link
Collaborator

thshdw commented Oct 20, 2016

@WorldWideWebb Thanks for the update!

@Franklin88
Copy link
Author

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
Copy link
Collaborator

thshdw commented Oct 25, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants