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

xtrace output doubles backslashes and single-quotes #700

Closed
Crestwave opened this issue Apr 7, 2020 · 4 comments
Closed

xtrace output doubles backslashes and single-quotes #700

Crestwave opened this issue Apr 7, 2020 · 4 comments

Comments

@Crestwave
Copy link
Contributor

Crestwave commented Apr 7, 2020

I'm guessing this isn't intended because you can run a command from the xtrace output and get a completely different result; this tripped me up for quite a while when debugging for #679.

osh$ set -x
osh$ echo '\'
+ echo '\\'
\
@andychu
Copy link
Contributor

andychu commented Apr 7, 2020

OK, yeah I can change this to use some shell routines, e.g. for %q or something. Right now it's using Python syntax with repr()!!

@andychu
Copy link
Contributor

andychu commented Apr 7, 2020

One thing I noticed is that for a string with newlines like

x=$'one\ntwo'

bash actually prints a real newline in the set -x format. But it could use the printf %q or ${x@Q} format which gives you back a string in the $'' format.

mksh does that.

I'm not sure exactly what to do for OSH yet, but I'm looking at it. Right now we don't have a routine that outputs $'' format. I wanted to "standardize" around CSTR in #582, but that could also be confusing because the format uses '\\' for a single backslash.

If it were $'\\' or c'\\' it could be less confusing.

@andychu
Copy link
Contributor

andychu commented Apr 7, 2020

Weird, bash does print non-printable characters with $'' like $'\003', but it doesn't print newlines like that.

So yeah the goal of CSTR in #582 is to come up with one format rather than 10 different little buggy formats that bash has. There are similar issues when you try to complete filenames with newlines, etc.

andychu pushed a commit that referenced this issue Apr 7, 2020
andychu pushed a commit that referenced this issue Apr 10, 2020
This is done with the "QSN" encoder.

Addresses issue #700.
@andychu
Copy link
Contributor

andychu commented Apr 10, 2020

OK I fixed this -- I wrote a proper shell string encoder! It uses '' properly, and it uses $'' if it needs to use backslash escapes.

(I generalized this to QSN which is the new name for CSTR .. there is a thread on Zulip about it if anyone's interested.)

@andychu andychu closed this as completed Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants