Hacker News new | ask | show | jobs
by jsmeaton 4369 days ago
I'll bite. What should we be using instead of `if [ $? -ne 0 ]`? Because that's pretty standard in my (admittedly very basic) bash.
1 comments

Instead of

somecommand

if [ $? -ne 0 ]; then echo "it failed"; fi

the parent commenter presumably wants to see

if ! somecommand; then echo "it failed"; fi

Or:

    somecommand || echo "it failed"
if it's just one statement. There are some cases where it just looks more natural. For example:

    start_service || log "already started"