Skip to content
New issue

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

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

Already on GitHub? # to your account

if-then-else example does not work #1569

Closed
zbuc opened this issue Jan 3, 2018 · 7 comments
Closed

if-then-else example does not work #1569

zbuc opened this issue Jan 3, 2018 · 7 comments
Labels

Comments

@zbuc
Copy link

zbuc commented Jan 3, 2018

The example for if-then-else in the documentation does not work correctly when you try to run it in the linked jqplay editor:

https://stedolan.github.io/jq/manual/#example74

https://jqplay.org/jq?q=%27if%20.%20%3D%3D%200%20then%0A%20%20%22zero%22%0Aelif%20.%20%3D%3D%201%20then%0A%20%20%22one%22%0Aelse%0A%20%20%22many%22%0Aend%27&j=2

Results:

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
'if . == 0 then
jq: 1 compile error
exit status 3
@pkoppstein
Copy link
Contributor

@zbuc - When using jqplay, you don't include the outermost quotation marks. Same thing if the jq program goes in a file. Indeed, the outermost quotation marks are sometimes not needed at all.

@zbuc
Copy link
Author

zbuc commented Jan 3, 2018

I followed the link directly from the documentation page, and did not manually change anything. It does not work as linked from the documentation.

I tried removing the single quotes, and it does work. This seems like a defect in the links included in the documentation.

@nicowilliams
Copy link
Contributor

@zbuc That's an example for you to use on a local shell, not on jqplay. I'm sorry, but there's no way to make the examples work for both.

@zbuc
Copy link
Author

zbuc commented Jan 3, 2018

Then why is there a link to run it on jqplay if it doesn't work?

zbuc added a commit to zbuc/jq that referenced this issue Jan 3, 2018
Use multiline match on jqplay "run" link generation in documentation.
@zbuc
Copy link
Author

zbuc commented Jan 3, 2018

@nicowilliams here, I found and fixed the bug. The regex being used only worked properly on single-line examples and failed on multiline ones.

#1570

@nicowilliams nicowilliams reopened this Jan 3, 2018
@nicowilliams
Copy link
Contributor

@zbuc Oh! I never knew about that feature (the Run button). I use NoScript, and wasn't enabling the required origin for that...

@itchyny
Copy link
Contributor

itchyny commented Jun 4, 2023

This has been resolved by #1716, and also the commit 048acee in #1825 removes the newlines from the example, and the page was rebuilt at 76c044f, the issue no longer happens.

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

No branches or pull requests

4 participants