#!/bin/sh # Yes, you can execute this whole script for demonstration. # Of course you also remember comments, the here document, and the : # command, right? :-) Okay, so I effectively (but not literally) # comment out the part between the pairs of __EOT__ without having to # individually comment out most or all the lines in the section. >>/dev/null 2>&1 : << \__EOT__ # while syntax (until syntax is the same, just use until instead # of while, and the sense of the test is reversed): while list # list remember definition of list, list can also be rather complex; # ---- return value of list determines if list within the loop runs # need a newline or semicolon before do do # need whitespace (one or more blanks, tabs, and/or newlines) # between do and list (so do can be recognized as keyword and not # part of some other word) list # need a newline or semicolon between list and done done __EOT__ # Typical fairly readable use in scripts: n=1 while [ "$n" -le 3 ] do echo "$n" n=`expr "$n" + 1` done # somewhat less readable version with minimum whitespace and no semicolons: n=1 while [ "$n" -le 3 ] do echo "$n" n=`expr "$n" + 1` done # without newlines: n=1; while [ "$n" -le 3 ]; do echo "$n"; n=`expr "$n" + 1`; done # somewhat less readable version with minimum whitespace and no newlines # within the command: n=1;while [ "$n" -le 3 ];do echo "$n";n=`expr "$n" + 1`;done #and an until example that does essentially the same thing; #since until reverses the sense of the test, we likewise reversed the logic in #the test itself so the result would be essentially the same: n=1 until [ "$n" -gt 3 ] do echo "$n" n=`expr "$n" + 1` done