From 7458bfd3d947c9b45ec9c83cfbe33a572d6d6671 Mon Sep 17 00:00:00 2001 From: rowlap Date: Fri, 5 Oct 2018 09:29:33 +0100 Subject: [PATCH] Add more explanation of chained operators --- SC2015.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SC2015.md b/SC2015.md index 1183faf..a7809a1 100644 --- a/SC2015.md +++ b/SC2015.md @@ -29,5 +29,16 @@ For the code sample above, if the script was run with stdout closed for any reas If an `if` clause is used instead, this problem is avoided. +### Boring detail: + + +We can think of the example above as +```sh +((([[ $dryrun ]]) && echo "Would delete file") || rm file) +``` +expressing the left-associativity of the `&&` `||` operators. + +Whenever a command (strictly, a pipeline) succeeds or fails, the execution proceeds following the next `&&` (for success) or `||` (for failure). + ### Exceptions Ignore this warning when you actually do intend to run C when either A or B fails.