I have the following snippet of code where I intend to:
Iterate 5 times the loop;
get a line from a file (each iteration I need the next line fetched);
use the line as a title for a file;
put a timestamp in the beginning of it;
use the line as argument for ping; print some sentences informing the user about the progress of the code;
The iteration already works.
If I skip the sed part, everything works, but I run the ping 5 times against the same target.
Each line of the file hosts.txt has a single IP address which I intend to ping.
for ((i>=1;i<=5;i++)) do sed -n "$i p" hosts.txt | read output touch "$output.txt" date >> "$output.txt" printf "\nComeçando o teste de $output." printf "\nTeste em andamento." ping -c 10 -i 1 "$output" >> "$output.txt" done
I believe the problem is that I'm doing something wrong about sed syntax. If I try on bash directly
sed -n 1p hosts, I get the first line. But as I need that number to be $i, if I put $i right before p bash interprets ip as a variable instead of variable i plus argument p after it.
How can I correct this behaviour and not mess this thing again?