Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
This will notify us if the file is empty:
[[ ! -s $file ]] && echo "hello there I am empty file !!!"
But how to check if a file has blank spaces (spaces or tabs)?
cat $file | tr -s " " > $file; [ ! -s $file ] && echo "hello there I am empty file !!!"
tr -s " " > $file; [ ! -s $file ] && echo "hello there I am empty file !!!"
Just grep for a character other than space:
grep -q '[^[:space:]]' < "$file" &&
printf '%s\n' "$file contains something else than whitespace characters"
echo "Non empty string" | grep -q '[^[:space:]]'
Required, but never shown
1 year, 11 months ago
1 year, 6 months ago