Thursday, 12 July 2018

shell script - Bash delete file when variable = x


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, break the loop and prompt the user to start again). I've 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 :)



Answer



[ is a command (an alias for test, in fact). You should separate it by whitespace from the surrounding text.


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...