So I ran ips=$(arp | awk '{print $1}') to save all the IP addresses retrieved from the arp command into a variable, ips. echo of ips gives me Address 192.168.10.100 192.168.10.101 192.168.10.1. I am assuming that Address 192.168.10.100 192.168.10.101 192.168.10.1 is saved as string in the ips variable. What I want is a way to loop through the variable ips and maybe save the one in a variable, ip, do something with it, and move to next one.
Asked
Active
Viewed 4,074 times
1
Christopher
- 15,611
- 7
- 51
- 64
Fazle Rabbi
- 506
- 1
- 5
- 15
1 Answers
2
Space is the default field separator so a simple for loop can handle this without issue. Be very careful when doing this because you can end up with unexpected results very easily doing these types of loops.
ips=$(arp | awk '{print $1}')
for ip in $ips
do
#Work here
echo IP: $ip
done
Zachary Brady
- 4,200
- 2
- 17
- 40