Script won't loop through files like planned

0

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.

QuyNguyen2013

Posted 2014-07-29T00:21:24.673

Reputation: 499

Define what you mean by "it won't work" beside being in a different directory now – Tyson – 2014-07-29T00:33:05.153

Answers

2

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" ].

Valmiky Arquissandas

Posted 2014-07-29T00:21:24.673

Reputation: 1 770