On Wed, 27 Dec 2023 23:42:55 +0300, Andrei Borzenkov <arvidjaar@gmail.com> wrote:
On 27.12.2023 23:26, Daniel Bauer wrote:
[...] Now when I have NO png-files (but jpg-files) in the "png-directory", in my opinion the script should do just nothing, because there is nothing to process in the for-loop.
for-loop is not aware about files. It works with strings. That some strings are the result of the pathname expansion is irrelevant for the for-loop. In this case it gets string *.png.
If you want for-loop to get empty string list (and really do nothing) set shell option nullglob. Or explicitly test inside your for-loop for $bild being equal "*.png" (which will result in the false positive if there is real file with the name *.png).
Along with Andrei's "nullglob" suggestion, adding a file check wouldn't hurt: cd "$png_directory" || exit shopt -s nullglob for bild in *.png do if [ ! -f "$bild" ] ;then printf 'strange_script: not a file: %s\n' "$bild" >&2 exit 2 fi [...] done -- Robert Webb