Posted By: Anonymous
I have a file called diff.txt. I Want to check whether it is empty.
I wrote a bash script something like below, but I couldn’t get it work.
if [ -s diff.txt ] then touch empty.txt rm full.txt else touch full.txt rm emtpy.txt fi
Misspellings are irritating, aren’t they? Check your spelling of
empty, but then also try this:
#!/bin/bash -e if [ -s diff.txt ] then rm -f empty.txt touch full.txt else rm -f full.txt touch empty.txt fi
I like shell scripting a lot, but one disadvantage of it is that the shell cannot help you when you misspell, whereas a compiler like your C++ compiler can help you.
Notice incidentally that I have swapped the roles of
full.txt, as @Matthias suggests.