#!/bin/csh -f # show_that_semicolons_in_aliases_break_short_circuits # ----------------------------------------------------------------------------- # C shell script to demonstrate that aliases containing semicolons can break # the short circuit logic of the && operator on an if statement. Problem # occurs in macOS 11.1, but works fine on Linux 3.2.22-35.60.amzn1.x86_64. # ----------------------------------------------------------------------------- set timestamp = `date "+%Y_%m_%d__%H_%M_%S"` set tempfile = "/tmp/$0:t_$$_${timestamp}_no_such_file" alias alias_with_semicolons 'ls $tempfile ; ls -d .' echo "------------------------------------------------------------------------" echo "Test 1:" echo "Watch for the 'No such file or directory' error message from the ls" echo "command. It will be followed by a line containing a single dot." echo "Then a line saying 'Short circuit is broken due to semicolon', if it is." echo "Otherwise, no more output before the line of hyphens because the short" echo "circuit happened." echo "Expected results:" echo "macOS 11.1: See the message because the short" echo " circuit is broken by the semicolon." echo "Linux 3.2.22-35.60.amzn1.x86_64: See the message because the short" echo " circuit is broken by the semicolon." pause alias_with_semicolons && echo Short circuit is broken due to semicolon echo "------------------------------------------------------------------------" pause alias alias_with_semicolons 'pushd $tempfile ; ls -d .' echo "" echo "------------------------------------------------------------------------" echo "Test 2:" echo "Watch for the 'No such file or directory' error message." echo "Watch to see if it's followed by a line containing a single dot." echo "If not, the entire script aborted as soon as the builtin pushd command" echo "failed." echo "Expected results:" echo "macOS 11.1: See the dot because the rest of the" echo " script line executed before the abort." echo "Linux 3.2.22-35.60.amzn1.x86_64: No dot because the script aborted" echo "" echo "After that, watch for the 'Short circuit is broken due to semicolon'" echo "message. If so, because of the semicolon, the rest of the line was" echo "executed instead of being short circuited." echo "Expected results:" echo "macOS 11.1: See the message because the short" echo " circuit is broken by the semicolon." echo "Linux 3.2.22-35.60.amzn1.x86_64: No message because the script aborted" echo "" echo "Then watch for a message saying the script completed normally, which" echo "means it didn't abort at all." echo "Expected results:" echo "macOS 11.1: No message because the script aborted" echo " after completing the line containing" echo " the failed pushd command." echo "Linux 3.2.22-35.60.amzn1.x86_64: No message because the script aborted" echo " immediately at the failed pushd." pause alias_with_semicolons && echo Short circuit is broken for builtins also echo "------------------------------------------------------------------------" pause alias alias_with_semicolons 'pushd $tempfile ; ls -d .' echo "" echo "------------------------------------------------------------------------" echo "Test 3:" echo "If short circuit is broken for builtins also, it will say so after the" echo "'No such file or directory' error message." echo "If error in pushd and other builtins aborts the script, no more output." echo "Otherwise, the script will say it completed normally." pause alias_with_semicolons && echo Short circuit is broken for builtins also echo "------------------------------------------------------------------------" pause echo "Script completed normally. Not aborted by error in call to builtin."