is_dir_empty(){
for file in "$1"
do
if [ "$file" != "$1" ]; then
return 0
fi
done
echo "return 1"
return 1
}
file="/home/tmp/*.sh"
if is_dir_empty "$file"; then
echo "empty"
else echo "not empty"
fi
it outputs
return 1 not empty
so is_dir_empty returned 1 but if condition evaluated to false somehow…. why?
Because shell scripts follow the Unix convention of expecting utilities to return zero for success and non-zero for failure, so boolean conditions are inverted.