On Tue, Apr 23, 2019 at 9:24 AM Hadrien Lacour <hadrien.lac...@posteo.net> wrote: > What if "$1" is empty? POSIX sh doesn't have the nullglob shop, you know.
[ "$1" ] || exit # add a message if you want [ -d "$1" ] || exit # if you want to check that the directory exists for p in "$1"/*; do [ -e "$p" ] || continue; ... # if you want to make sure the glob expanded and files exist Another option is: [ "$1" ] || exit set -- "$1"/* [ -e "$1" ] || exit for p do ...; done And in reality use something to print an error message, not just exit. E.g.: die() { printf %s\\n "$*" >&2; exit 1; } [ "$1" ] || die Argument is empty [ -d "$1" ] || die "Directory does not exist: $1" etc.