I want to check whether a directory has files or not in bash. My code is here.
for d in {,/usr/local}/etc/bash_completion.d ~/.bash/completion.d do
[ -d "$d" ] && [ -n "${d}/*" ] &&for f in $d/*; do [ -f "$f" ] && echo "$f" && . "$f" done done
The problem is that "~/.bash/completion.d" has no file. So, $d/* is regarded as simple string "~/.bash/completion.d/*", not empty string which is result of filename expansion. As a result of that code, bash tries to run
. "~/.bash/completion.d/*"
and of course, it generates error message.
Can anybody help me?