[SOLVED] A question about for loop (increasing two parameters)
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
A question about for loop (increasing two parameters)
Hi All,
I have a question about the for loop in Bash, I would like to produce plenty of lines using for loop where the first field increases by one but only when the second one reaches its limit.
I would like the third octet of the IP address 1.1.1.1 to change to the number 2 but only when the fourth octet reaches the number 5.
for i in {1..5};do echo "ip route add 1.1.1.$i/32 via 192.168.168.1";done
here is an example of what I need my for loop to do:
ip route add 1.1.1.1/32 via 192.168.168.1
ip route add 1.1.1.2/32 via 192.168.168.1
ip route add 1.1.1.3/32 via 192.168.168.1
ip route add 1.1.1.4/32 via 192.168.168.1
ip route add 1.1.1.5/32 via 192.168.168.1
ip route add 1.1.2.1/32 via 192.168.168.1
ip route add 1.1.2.2/32 via 192.168.168.1
ip route add 1.1.2.3/32 via 192.168.168.1
ip route add 1.1.2.4/32 via 192.168.168.1
ip route add 1.1.2.5/32 via 192.168.168.1
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.