szabgab / code-maven.com

The content of the Code-Maven site
https://code-maven.com/
30 stars 54 forks source link

Mistake on line 6 of examples/shell/cli.sh in the bash getopt post #181

Closed bivalence closed 6 months ago

bivalence commented 8 months ago

In this post:

https://code-maven.com/bash-getopt-processing-command-line-arguments

this line in the examples/shell/cli.sh script (line 6 of the script):

[ $? -eq 0 ] || {

should be:

[ $? -ne 0 ] || {

Thanks for posting the example; it was helpful.

szabgab commented 7 months ago

Why do you think so? The meaning of that line, as I understand it, is:

Either the previous command is successful (exit 0) or || do the block (echo and exit)

However, I realized now that this is rather unusual. I think this is the common shell style, but it is different from what you'd write in most languages and so it is confusing.

I changed the code in the post and added some explanation.

Thanks for your comment!

szabgab commented 6 months ago

closing for lack of additional comment.