On Tue, Apr 23, 2019 at 09:30:14AM -0700, Evan Gates wrote:
> 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.
>
That was just shitposting. I use `find` to avoid most of the UNIX braindamage
in this case.
Received on Tue Apr 23 2019 - 21:41:36 CEST
This archive was generated by hypermail 2.3.0
: Tue Apr 23 2019 - 21:48:08 CEST