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

Regression in if-then-else docs #2139

Closed
amagee opened this issue Jun 10, 2020 · 5 comments
Closed

Regression in if-then-else docs #2139

amagee opened this issue Jun 10, 2020 · 5 comments
Labels

Comments

@amagee
Copy link

amagee commented Jun 10, 2020

The docs at https://stedolan.github.io/jq/manual/ currently say:

Checking for false or null is a simpler notion of "truthiness" than is found in Javascript or Python, but it means that you'll sometimes have to be more explicit about the condition you want. You can't test whether, e.g. a string is empty using if .name then A else B end, you'll need something more like if .name then A else B end instead.

Note the two expressions there are identical.

Seems to be a regression introduced in 8a02b2c

@ghost
Copy link

ghost commented Jul 28, 2020

I noticed this as well.

I would also offer that the "else" is not optional (as documented), but is (now) required, as shown in the following code examples (for jq 1.6):

> print '{"labels":{"owner1":"dls","archived":"","owner2":"data-services"}}' | jq -r '.labels? | length>0 '                                        
true

> print '{"labels":{"owner1":"dls","archived":"","owner2":"data-services"}}' | jq -r '.labels? | if length>0 then "present" else "not present" end'
present

> print '{"labels":{"owner1":"dls","archived":"","owner2":"data-services"}}' | jq -r '.labels? | if length>0 then "present" end'                   
jq: error: syntax error, unexpected end (Unix shell quoting issues?) at <top-level>, line 1:
.labels? | if length>0 then "present" end                                      
jq: error: Possibly unterminated 'if' statement at <top-level>, line 1:
.labels? | if length>0 then "present" end           
jq: 2 compile errors

@itchyny
Copy link
Contributor

itchyny commented Jul 29, 2020

If you are using jq 1.6, please refer to https://stedolan.github.io/jq/manual/v1.6/.
In the master version, else is optional as implemented by #1825.

 % print '{"labels":{"owner1":"dls","archived":"","owner2":"data-services"}}' | jq -r '.labels? | if length>0 then "present" end'
present
 % jq --version
jq-master-a17dd32

@ghost
Copy link

ghost commented Jul 29, 2020 via email

@itchyny
Copy link
Contributor

itchyny commented Jul 30, 2020

Current latest released version is 1.6. https://stedolan.github.io/jq/manual/ is the manual for development version and you can build yourself as described in README.md (https://github.com/stedolan/jq/blob/master/README.md).

@itchyny itchyny added the docs label Jun 3, 2023
@itchyny
Copy link
Contributor

itchyny commented Jun 5, 2023

The document was fixed at #2271 (cc4efc4) in May 2021, so closing the issue.

@itchyny itchyny closed this as completed Jun 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants