: , , . , ( ), .
read . , , , . , ( , ): IFS . . while IFS= read , IFS=; while read..? . , -r read, , .
while IFS= read -r line; do
if [ -z "$line" ]; then
echo empty line
fi
done <"$1"
, :
while IFS= read -r line; do
case "$line" in
'') echo "empty line";;
*[![:space:]]*) echo "non-blank line";;
*) echo "non-empty blank line";;
esac
done <"$1"
Bash , :
while IFS= read -r line; do
if [[ "$line" =~ ^$ ]]; then
echo "empty line"
elif [[ "$line" =~ ^[[:space:]]+$ ]]; then
echo "non-empty blank line"
else
echo "non-blank line"
fi
done <"$1"
( , ):
while IFS= read -r line; do
if [[ "$line" == "" ]]; then
echo "empty line"
elif [[ "$line" != *[![:space:]]* ]]; then
echo "non-empty blank line"
else
echo "non-blank line"
fi
done <"$1"
- , grep:
if grep -qxF '' <"$1"; then
echo "$1 contains an empty line"
fi
, :
if grep -Ex '[[:space:]]+' <"$1"; then
echo "$1 contains a non-empty blank line"
fi