GNU bash, version 4.3.42(1)-release (arm-openwrt-linux-gnu)
I'm trying to script an iptables rule using a bash array.
$NETID is used to create network addresses. For example, 192.168.10.0/24, 192.168.20.0/24, etc.
I'm trying to create a temporary variable ($NETID_TMP) where the "i" in ${NETID[@]} is removed from $NETID_TMP. For example, if "i" = 10, NETID_TMP=(20 30 40).
Script:
#!/opt/bin/bash
NETID=(10 20 30 40)
for (( i=0; i<${#NETID[@]}; i++ )); do
NETID_TMP=(${NETID[*]})
unset NETID_TMP[${NETID[i]}]
iptables -I FORWARD -s 192.168.${NETID[i]}.0/24 -d 192.168.${NETID_TMP[0]}.0/24,192.168.${NETID_TMP[1]}.0/24,192.168.${NETID_TMP[2]}.0/24 -j DROP
done
The result should be ...
iptables -I FORWARD -s 192.168.10.0/24 -d 192.168.20.0/24,192.168.30.0/24,192.168.40.0/24 -j DROP
iptables -I FORWARD -s 192.168.20.0/24 -d 192.168.10.0/24,192.168.30.0/24,192.168.40.0/24 -j DROP
iptables -I FORWARD -s 192.168.30.0/24 -d 192.168.10.0/24,192.168.20.0/24,192.168.40.0/24 -j DROP
iptables -I FORWARD -s 192.168.40.0/24 -d 192.168.10.0/24,192.168.20.0/24,192.168.30.0/24 -j DROP