Subject: Re: equivalent of sockstat?
To: Geert Hendrickx <ghen@hmacs.cmi.ua.ac.be>
From: David Laight <david@l8s.co.uk>
List: netbsd-help
Date: 01/03/2005 20:16:08
> I tried to work something out in /bin/sh, but it's not evident since
> /bin/sh does not have associative arrays,
You can often use 'eval' to implement them by token pasting names. eg:
while read tag value
do
eval tag_$tag=\$value
done
# later
for tag in $tag_list
do
eval value=\$tag_$tag
echo tag $tag = $value
done
If the tags contain non-alphanumerics you have a slight problem,
specific characters can be deleted by:
IFS="<invalid_chars>"
set -- $tag
IFS=
tag="$*"
Or replaced with (for example) an underscore with the similar
IFS="<invalid_chars>"
set -- $tag
IFS=_
tag="$*"
(Remember to reset IFS for teh next line)
> and "for" parses netstat's output word by word instead of line by line.
IFS is your friend here... add:
nl='
'
near the top of the script, then add IFS=$nl before the 'for'.
You may want to reset it afterwards (default is space/tab/newline).
David
--
David Laight: david@l8s.co.uk