Bash delete file when variable = x

Posted by twigg on Super User See other posts from Super User or by twigg
Published on 2012-09-08T01:13:45Z Indexed on 2012/09/08 3:40 UTC
Read the original article Hit count: 447

Filed under:

I'm creating a bash script which reboots the system at each reboot it adds a new line to a text file, I then read the text file before each reboot. Once the variable holding the number of lines reaches say 10 I want the script to delete the text file (at which point on the next reboot it will see the file isn't there, brake the loop and promote the user to start again). I tried this:

exec < text.txt
nol=0
while read line
do
nol=`expr $nol + 1`
done

reboot_count=10
if ["$nol" == "$reboot_count"];
then
rm text.txt
fi

but this doesn't seem to be working, all help is appreciated :)

© Super User or respective owner

Related posts about bash