use*_*833 6 command-line files newlines
如果您打开一个文件,vim并且该文件EOL的最后一行末尾没有,那么编辑器会将其报告为[noeol]. 在打开它之前如何确定这一点vim?(有没有我可以发出的命令来确定这一点?)
tail -c 1 输出其输入的最后一个字符(更准确地说,最后一个字节)。
命令替换去除尾随的换行符,因此如果文件的最后一个字符$(tail -c 1 <…)是换行符,则为空。如果最后一个字符是空字节(在大多数 shell 中),它也是空的,但文本文件没有空字节。
请记住,空文件不需要额外的换行符。
if [ ! -s "$filename" ]; then
echo "$filename is empty"
elif [ -z "$(tail -c 1 <"$filename")" ]; then
echo "$filename ends with a newline or with a null byte"
else
echo "$filename does not end with a newline nor with a null byte"
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1174 次 |
| 最近记录: |