我有个文件叫100.我想判断一下它是否是空的.
我写了一个bash脚本,如下所示,但我无法让它工作.
if [ -s diff.txt ]
then
touch empty.txt
rm full.txt
else
touch full.txt
rm emtpy.txt
fi
我有个文件叫100.我想判断一下它是否是空的.
我写了一个bash脚本,如下所示,但我无法让它工作.
if [ -s diff.txt ]
then
touch empty.txt
rm full.txt
else
touch full.txt
rm emtpy.txt
fi
拼写错误令人恼火,不是吗?判断empty
的拼写,但也可以try 以下方法:
#!/bin/bash -e
if [ -s diff.txt ]; then
# The file is not-empty.
rm -f empty.txt
touch full.txt
else
# The file is empty.
rm -f full.txt
touch empty.txt
fi
我很喜欢shell脚本,但是它的一个缺点是shell在拼写错误时不能帮助你,而像C++编译器这样的编译器可以帮助你.
顺便注意一下,正如@Matthias所说,我已经交换了empty.txt
和full.txt
的角色.