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

set -x breaks piping #926

Closed
graf0 opened this issue Oct 7, 2022 · 2 comments · Fixed by #927
Closed

set -x breaks piping #926

graf0 opened this issue Oct 7, 2022 · 2 comments · Fixed by #927

Comments

@graf0
Copy link
Contributor

graf0 commented Oct 7, 2022

Hello!

When you enable tracer via set -x, it breaks pipes.

how to reproduce?

install jq, then:

#!/bin/gosh
set -x
echo '{"number":1}' | jq '.number'

efect of this script should be:

1

is:

+ jq .number
parse error: Invalid numeric literal at line 1, column 2

it could be even simpler without jq:

#!/bin/gosh
set -x
echo "test" | tee test.txt

in test.txt there is following content:

+ echo test
test

where is problem?

in file interp/trace.go, line 28 I think we should set stderr as output stream. Otherwise printed traces become input of next command in the pipe.

@mvdan
Copy link
Owner

mvdan commented Oct 7, 2022

Nicely spotted - I think you're right:

$ bash -x -c 'echo foo' >/dev/null
+ echo foo
$ bash -x -c 'echo foo' 2>/dev/null
foo

Want to send a PR? cc @riacataquian

@graf0
Copy link
Contributor Author

graf0 commented Oct 8, 2022

Want to send a PR? cc @riacataquian

Sure - you have it :)

mvdan pushed a commit that referenced this issue Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants