[lug] My script work on real "ksh" but not "bash"
Jeffrey Haemer
jeffrey.haemer at gmail.com
Thu Sep 4 15:54:02 MDT 2008
Dave,
It's not the loop that's biting you, it's the pipe.
$ x=2.718; x=3.14; echo $x
3.14
$ x=6.02e23; x=6 | x = 9; echo $x
6.02e23
Bash runs each piece of a pipeline in its own subshell.
Hope this helps.
On Thu, Sep 4, 2008 at 1:45 PM, Dave Pitts <dpitts at cozx.com> wrote:
> 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
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>
--
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell]
http://goyishekop.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20080904/5ff275f8/attachment.html>
More information about the LUG
mailing list