You aren't expandingEdit: as @StéphaneChazelas pointed out, the parameterproblem is likely that your script isn't being invoked with $COUNTbash in your arithmetic expression, so it's trying to run a commandand the COUNT(( )) and redirect that toconstruct won't work. Try running it from a file MAX_BACKUPSbash. shell or with bash my_script.sh
Also, that rm has the potential to fail spectacularly. Please read this FAQ.