Script won’t loop through files like planned

bashlogging

I got this script that loops through log files, but I changed something and it doesn't work:

#!/bin/sh
n=
while true
do
    fname="trace$n.log"
    [ -f "$fname" ] || break
    n=$(($n+1))
done
traceroute google.com >"$fname"

Changed to:

#!/bin/sh
n=
while true
do
    fname="trace$n.log"
    [ -f "$fname" ] || break
    n=$(($n+1))
done
traceroute google.com >~/Scripts/logs/"$fname"

The last line was changed and now it won't work!
Help would be appreciated!
Thank you.

Best Answer

What do you mean with "it won't work"?

Note that your [ -f "$fname" ] is testing the wrong directory; make it [ -f ~/Scripts/logs/"$fname" ].

Related Question