linux check if there is a blank line at the end of the file

Examples are as follows:

[ -z `sed -n '$p' test.txt` ] && echo 最后一行为空行
[ -n `sed -n '$p' test.txt` ] && echo 最后一行不是空行

[ -z `tail -n 1 test.txt` ] && echo 最后一行为空行
[ -n `tail -n 1 test.txt` ] && echo 最后一行不是空行

[ -z `awk 'END {print}' test.txt` ] && echo 最后一行为空行
[ -n `awk 'END {print}' test.txt` ] && echo 最后一行不是空行

 

 

Guess you like

Origin blog.csdn.net/whatday/article/details/113861198