I'm working on a script to parse command output and I'm using this
probably yucky flawed sh construct:
TARGET=$1
nbtscan -vs' ' $TARGET |
while read line; do
COMP_NAME=$(echo $line | awk '$3 == "00U" {print $2}')
[ -n "$COMP_NAME" ] && echo "\$COMP_NAME = $COMP_NAME"
DOM_NAME=$(echo $line | awk '$3 == "00G" {print $2}')
[ -n "$DOM_NAME" ] && echo "\$DOM_NAME = $DOM_NAME"
MAC_ADDR=$(echo $line | awk '$2 == "MAC" {print $3}' | tr '-' ':')
[ -n "$MAC_ADDR" ] && echo "\$MAC_ADDR = $MAC_ADDR"
done
echo "\$COMP_NAME = $COMP_NAME"
echo "\$DOM_NAME = $DOM_NAME"
echo "\$MAC_ADDR = $MAC_ADDR"
So I'm outputting the value of three variables both within the while
loop where they're set as well as outside the while loop when
terminated. When this is executed the variable seems to not be set /
not contain values outside of the while loop:
$ ./test-netbios 10.1.1.1
$COMP_NAME = CAFFEINEADDICTS
$DOM_NAME = GLOBAL
$MAC_ADDR = 00:11:43:d1:ad:d7
$COMP_NAME =
$DOM_NAME =
$MAC_ADDR =
I'm clearly not understanding something with scoping here, can anyone
share a clue stick?
-- Darren Spruell phatbuckett@gmail.com -- List Info: http://metabug.org/mail/ List Archives: http://metabug.org/archive/talk/ To Unsubscribe: Mail mailto:talk+unsubscribe@metabug.orgReceived on Wed Jul 2 14:24:58 2008
This archive was generated by hypermail 2.1.8 : Wed Jul 02 2008 - 14:24:58 EDT