[lug] My script work on real "ksh" but not "bash"
Dave Pitts
dpitts at cozx.com
Thu Sep 4 13:45:43 MDT 2008
Hello:
I've got a script (below) that works as expected under the Korn Shell
(ksh) but fails under Bash. It acts as if the variables have some kind
of scope issues as they are null after exiting the loop.
It's probably something simple; but I can't see the problem...
The script:
#!/bin/bash
typeset srclist=""
typeset tarlist=""
if [ "$1" = "" ];then
echo "Usage: $0 statusfile"
exit 1
fi
cat $1 | while read line
do
if [ "${line}xx" = "xx" ]; then
break
fi
tag=`echo $line | awk '{print $2}'`
if [ "${tag}xx" = "Volume:xx" ]; then
while [ "$line" != "Component Volumes:" ]
do
read line
done
endline=""
while [[ -z "${endline}" ]]
do
read line
if [[ "$?" -ne 0 ]]; then
echo "ReadStatusFailed:"
exit 1
fi
case "${line}" in
*\ SOURCE\ *|*\ SOURCE)
srcvol=`echo $line | awk '{print $1}'`
;;
*\ UPTODATE\ *|*\ UPTODATE)
tarvol=`echo $line | awk '{print $1}'`
endline="TARGET"
;;
*\ SCRATCH\ *|*\ SCRATCH)
endline="TARGET"
;;
esac
done
srclist="$srclist $srcvol"
tarlist="$tarlist $tarvol"
fi
echo "inloop: srclist = " $srclist ", tarlist = " $tarlist
echo " srcvol = " $srcvol ", tarvol = " $tarvol
done
echo "outloop: srclist = " $srclist ", tarlist = " $tarlist
if [[ -z "${srclist}" ]]; then
echo "IT's BROKE"
else
echo "It worked"
fi
exit
The data:
Group Volume: Vol1
Component Volumes:
/dev/dasdc1 SOURCE
/dev/dasdc2 UPTODATE
So, if anybody sees an issue here. Please let me know...
Thanks.
PS. re: System Load - I FINALLY got it all to work after they replaced
the disk drive and found some wrongly placed jumpers on the motherboard.
--
Dave Pitts PULLMAN: Travel and sleep in safety and comfort.
dpitts at cozx.com My other RV IS a Pullman (Colorado Pine).
http://www.cozx.com
More information about the LUG
mailing list