判断文件是否为空
我们知道在脚本中用 -z
可以判断字符串是否为空,那么对于文件来说,该怎么判断是否为空呢?
bash也提供了一个 -s
来判断文件是否为空,注意,当文件中 有内容 时候为 真
[ -s file.name ] || echo "file is empty"
参考
Last updated
Was this helpful?
我们知道在脚本中用 -z
可以判断字符串是否为空,那么对于文件来说,该怎么判断是否为空呢?
bash也提供了一个 -s
来判断文件是否为空,注意,当文件中 有内容 时候为 真
[ -s file.name ] || echo "file is empty"
Last updated
Was this helpful?