Trying to print range of ip addresses to a file. Instead of looping through the range it just prints one line containing the variable values.
cidr="192.168.0.1/24"
# range is bounded by network (-n) & broadcast (-b) addresses.
lo=$(ipcalc -n $cidr |cut -f2 -d=)
hi=$(ipcalc -b $cidr |cut -f2 -d=)
read a b c d <<< $(echo $lo |tr . ' ')
# echo $a.$b.$c.$d
read e f g h <<< $(echo $hi |tr . ' ')
# echo $e.$f.$g.$h
for ip in {$a..$e}.{$b..$f}.{$c..$g}.{$d..$h};
do
echo $ip > results.txt
done;
Current output is...
{192..192}.{168..168}.{0..0}.{0..255}
If given 192.168.0.1/24 looking for how to get the output to print each host in that network on each line in a file...
192.168.0.0
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
...
192.168.0.255
{$a..$e}.{$b..$f}.{$c..$g}.{$d..$h}will not work because brace expansion does not accept variables as arguments.evalevalrisks if the content is not under your control.