On Tue, Apr 23, 2019 at 9:24 AM Hadrien Lacour
<hadrien.lacour_AT_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.
Received on Tue Apr 23 2019 - 18:30:14 CEST
This archive was generated by hypermail 2.3.0
: Tue Apr 23 2019 - 18:48:08 CEST