Revision: 783 http://svn.savannah.gnu.org/viewvc/?view=rev&root=administration&revision=783 Author: iank Date: 2024-04-18 15:22:02 -0400 (Thu, 18 Apr 2024) Log Message: ----------- add note about nullglob
Modified Paths: -------------- trunk/sviki/fsf/bash-style-guide.mdwn Modified: trunk/sviki/fsf/bash-style-guide.mdwn =================================================================== --- trunk/sviki/fsf/bash-style-guide.mdwn 2024-04-18 06:26:33 UTC (rev 782) +++ trunk/sviki/fsf/bash-style-guide.mdwn 2024-04-18 19:22:02 UTC (rev 783) @@ -533,3 +533,17 @@ readonly this_file this_dir="${this_file%/*}" cd "$this_dir" ``` + + +Globing files needs `shopt -s nullglob` to do succinctly. Once you +realize you need nullglob, add it at the top of your script. It is very +easy to forget, so it is a good idea to put it at the top of all your +scripts. + + +``` +shopt -s nullglob +for f in dir/*; do + some-command $f +done +```