Oh no! There is a very important problem with this code. It should be
if [ -n "$(ls -A /path/to/dir)" ]; then
... Please update the answer before someone pastes this code into their server somewhere and a hacker figures out how to exploit it. If /path/to/dir
isn't empty, then the filenames there get passed as arguments to /bin/test
which is clearly not intended. Just add the -n
argument, problem solved. Thanks!