I'm writing some iptables scripts, and I want to write a function that takes an arbitrary number of parameters and consumes them two at a time. Here's an example:
#!/bin/sh
# Allow inbound sessions for a specific service
iptables --append INPUT --protocol $PROTO --destination-port $PORT \
--match state --state NEW --jump ACCEPT || exit 1
I found this thread that shows the right syntax for looping through an arbitrary number of arguments, but I don't know how to grab two arguments in each iteration. How do I get both $PROTO and $PORT from the caller (from $@, two args at a time)?
$PROTOand$PORTcome from? Where's your arbitrary number of parameters? What is an example of how you'd like this script to be called?