Re: Errors when reading a file in Bourne shell -- HELP
From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 07/26/03
- Next message: wil_at_perdition.wilcomm.NOSPAM.net: "Re: Best UNIX"
- Previous message: TheCageyBee: "Re: Errors when reading a file in Bourne shell -- HELP"
- In reply to: SK: "Errors when reading a file in Bourne shell -- HELP"
- Next in thread: SK: "Re: Errors when reading a file in Bourne shell -- HELP"
- Reply: SK: "Re: Errors when reading a file in Bourne shell -- HELP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 25 Jul 2003 22:36:43 GMT
On Fri, 25 Jul 2003 at 21:40 GMT, SK wrote:
> Hi
>
> I am trying to write a script to check the status of servers in the
> network and i wanted to enter the names into a file for future use. So
> I use the echo command as given below to redirect the values.
>
> echo SERVER SERVER_NAME TIMEOUT_VALUE > $ ${SERVER_INPUT_LISTING}
>
> In the script given below, I try to read back from the file and set
> the status flags according to the values read from the file and
> processing it. So when I used while-do for reading the file, the flags
> that i set inside the loop are not visible outside the loop.
>
> In the script below, the value of $EXIT_STATUS doesnt get displayed
> outside the loop. After I run the script, the first "Here I am" prints
> 1 or 2 but the second "here I am doesnt print anything.
>
> while read server
> do
> set ${server}
> SERVER=$1
> export SERVER
>
> SERVER_NAME=$2
> export SERVER_NAME
>
> TIMEOUT=$3
> export TIMEOUT
while read SERVER SERVER_NAME TIMEOUT
do
> SERVER_STATE="some value"
> if test -n "$SERVER_STATE"
What are you testing for? You know that $SERVER_STATE contains
characters; you just put them there.
> then
> ERROR_FLAG=1
> EXIT_STATUS=1
> echo "Exiting ..."
> break
> else
> EXIT_STATUS=2
> fi
>
> echo " here i am: $EXIT_STATUS "
>
> done < ${SERVER_INPUT_LISTING}
> echo " here i am: $EXIT_STATUS"
> exit
>
> Someone please help me clarify this prblem... your help will be very
> much appreciated...
You are probably using a Bourne shell which runs a loop with
redirected stdin in a subshell; therefore changes within the loop
cannot affect the script outside the loop.
You can get around this by enclosing the whole thing in braces and
doing the redirection outside them:
{
while read SERVER SERVER_NAME TIMEOUT
do
.......
done
echo " here i am: $EXIT_STATUS"
} < ${SERVER_INPUT_LISTING}
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: wil_at_perdition.wilcomm.NOSPAM.net: "Re: Best UNIX"
- Previous message: TheCageyBee: "Re: Errors when reading a file in Bourne shell -- HELP"
- In reply to: SK: "Errors when reading a file in Bourne shell -- HELP"
- Next in thread: SK: "Re: Errors when reading a file in Bourne shell -- HELP"
- Reply: SK: "Re: Errors when reading a file in Bourne shell -- HELP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|