Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Last active April 26, 2017 19:54
Show Gist options
  • Save ctrueden/ae0f024a0cdf2cb53c915d75b0759553 to your computer and use it in GitHub Desktop.
Save ctrueden/ae0f024a0cdf2cb53c915d75b0759553 to your computer and use it in GitHub Desktop.
The joy of shell scripting
$ if [ "condition" ]; then echo yes; else echo no; fi
yes
$ # Cool, but it's kind of verbose... is there a shorter way?
$ test "condition" && echo yes || echo no
yes
$ # Great! How succinct!
$ if [ "condition" ]; then cat nonexistentFile; else echo no; fi
cat: nonexistentFile: No such file or directory
$ # Aha, a non-zero exit code...
$ test "condition" && cat nonexistentFile || echo no
cat: nonexistentFile: No such file or directory
no
$ # Oh noez!!!!!!!!!!!!1111one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment