Controlling the loop
Having entered our loop, we may need to either exit the loop prematurely or perhaps exclude certain items from processing. If we want to process only directories in a listing, rather than every file of any type, then to implement this, we have loop control keywords, such as break
and continue
.
The break
keyword is used to exit the loop processing no more entries, whereas the continue
keyword is used to stop the processing of the current entry in the loop and resume the processing with the next entry.
Assuming we only want to process directories, we could implement a test within the loop and determine the file type:
$ for f in * ; do [ -d "$f" ] || continue chmod 3777 "$f" done
Within the loop we want to set permissions including the SGID and Sticky bits, but for the directories only. The *
search will return all files, the first statement within the loop will ensure that we only process directories. If the test is done for the current loop, the target fails the test and...