From ac40a6a396f19bbad9465ed37ac47caa46654d28 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 14 Jun 2018 08:45:04 +1000 Subject: [PATCH] docs: update --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 7a690cd..4a2af2d 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ scripts and not full blown utilities. * [Shorter `for` loop syntax.](#shorter-for-loop-syntax) * [Shorter infinite loops.](#shorter-infinite-loops) * [Shorter function declaration.](#shorter-function-declaration) + * [Shorter if syntax.](#shorter-if-syntax) * [Miscellaneous](#miscellaneous) * [Get the current date using `strftime`.](#get-the-current-date-using-strftime) * [Bypass shell aliases and functions.](#bypass-shell-aliases-and-functions) @@ -495,6 +496,24 @@ f()if true; then echo "$1"; fi f()for i in "$@"; do echo "$i"; done ``` +### Shorter if syntax. + +```sh +# One line +[[ "$var" == hello ]] && echo hi || echo bye +[[ "$var" == hello ]] && { echo hi; echo there; } || echo bye + +# Multi line (no else, single statement) +[[ "$var" == hello ]] && \ + echo hi + +# Multi line (no else) +[[ "$var" == hello ]] && { + echo hi + # ... +} +``` + ## Miscellaneous ### Get the current date using `strftime`.