A hacky, but bash-only, PID-free way:
test -e "$1/"* 2>/dev/null
case $? in;
1) return 0 ;;
*) return 1 ;;
This takes advantage of the fact that
test builtin exits with 2 if given more than one argument after
"$1"/* glob is expanded by bash. This results in one argument per file. So
if there are no files,
test -e "" is run, which obviously always fails,
i.e. returns 1 for "no".
If there is one file,
test -e "dir/file" is run, which returns 0.
But if there are more files than 1, bash reports it as usage error, i.e. 2.
case wraps the whole logic around so that only the first case, with 1 exit status is reported as success.
Possible problems I haven't checked:
There are more files than number of allowed arguments--I guess this could
behave similar to case with 2+ files.
Or there is actually file with an empty name--I'm not sure it's possible on any