Hacker News new | past | comments | ask | show | jobs | submit login

What happens if the next program in the pipe is not jb? Does jb also exit with a code?

For example `jb | jq`, where jq or a similar program discards the cancel character.

(Away from pc, unable to check right now.)




Good question! Yep, jb exits with non-zero:

    $ jb size:number=oops; echo $?
    json.encode_number(): not all inputs are numbers: 'oops'
    json(): Could not encode the value of argument 'size:number=oops' as a 'number' value. Read from inline value.
    ␘
    1
If you pipe the jb error into jq, jq fails to parse the JSON (because of the Cancel ctrl char) and also errors:

    $ jb size:number=oops | jq
    json.encode_number(): not all inputs are numbers: 'oops'
    json(): Could not encode the value of argument 'size:number=oops' as a 'number' value. Read from inline value.
    parse error: Invalid numeric literal at line 2, column 0

    $ declare -p PIPESTATUS
    declare -a PIPESTATUS=([0]="1" [1]="4")
So jq exits with status 4 here.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: