Got it!! Re:bash character substitution? Need help
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Fri Feb 6 19:40:37 UTC 2004
Hi again Grant,
No worries about replying now, I figured out a way to make it work.
Here is what I did (for the archives)...
#!/bin/bash
X='00:11:22:33:44:55>21,53,80-85'
for rule in ${X} ; do
echo "Rule: "${X}
echo "$rule" | {
IFS='>' read mac port
echo "MAC: "$mac" Ports: "$port
echo "$port" | {
IFS=','
for num in ${port} ; do
echo "Individual Port: "$num
echo "$num" | {
IFS='-' read fsp lsp
if [ "${lsp}" != "" ] ; then
echo "Port Range: "${fsp}":"${lsp}
else
echo "Single Port: "${fsp}
fi
}
done
}
}
done
Many thanks again!!
Madison
Grant Cullen wrote:
> Madison, the following will give the basic parsing.
>
> Good luck
>
> #!/bin/bash
> X='00:11:22:33:44:55>21,53,80-85'
> MAC=${X,1,17}
> [ ${#X} -gt 18 ] &&
> {
> # we have ports - length greater than 18
> IFS=','
> for PORT in ${x:18}
> do
> echo "iptable entry with port " $PORT
> done
> } ||
> {
> # no ports
> echo "iptable entry without ports"
> }
>
> Grant Cullen
> JADALL Consulting Ltd.
> grant.cullen-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org
> 416-706-4447
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list