0

In a Bash script, I would like to split a IP by dot delimiter. But When I am passing a variable in For Loop it is behaving like string.

StartIP=10.10.140.10
EndIP=10.10.140.15

StartIP_Prefix_1=`echo $StartIP | awk -F"\." '{print $1}'`
StartIP_Prefix_2=`echo $StartIP | awk -F"\." '{print $2}'`
StartIP_Prefix_3=`echo $StartIP | awk -F"\." '{print $3}'`
StartIP_Prefix_4=`echo $StartIP | awk -F"\." '{print $4}'`

EndIP_Prefix_3=`echo $EndIP | awk -F"\." '{print $3}'`
EndIP_Prefix_4=`echo $EndIP | awk -F"\." '{print $4}'`

IP_Prefix=$StartIP_Prefix_1.$StartIP_Prefix_2


IP_Range=$IP_Prefix.{$StartIP_Prefix_3..$EndIP_Prefix_3}.
{$StartIP_Prefix_4..$EndIP_Prefix_4}

for ip in $IP_Range
do
  echo $ip

done

After running the script, It is showing 10.10.{40..40}.{10..15}

expect : I want it show all the IPs like: 10.10.140.10 10.10.140.11 10.10.140.12 10.10.140.13 10.10.140.14 10.10.140.15

Please, Let me know if there any other option to find out IPs between two IPs.

avi
  • 1
  • 2
  • Not clear, please provide sample Input with expected sample output here in CODE TAGS. – RavinderSingh13 Jan 30 '18 at 06:34
  • This might help: [IP range generator script](https://stackoverflow.com/q/35681157/3776858) – Cyrus Jan 30 '18 at 06:38
  • Tangentially see also https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable – tripleee Jan 30 '18 at 07:03
  • All regular variables in Bash are strings. Some can be interpreted as numbers in some contexts, but you are fundamentally dealing with strings all the time. – tripleee Jan 30 '18 at 07:04

0 Answers0