Re: Errors when reading a file in Bourne shell -- HELP
From: SK (soundars_at_ecs.csus.edu)
Date: 07/27/03
- Next message: Charles Demas: "Re: Q for Unix guru's"
- Previous message: Alan Connor: "Re: Q: how do I open xterm, run command, and continue manual input?"
- In reply to: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Next in thread: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Reply: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jul 2003 17:36:13 -0700
Hi,
Thanks a ton for your response... I am trying to exit out of the
script from inside the do while and when I do an exit it exits only
the do while and not the shell itself. I rewote the code like this
(
while read server
do
set ${server}
SERVER=$1
export SERVER
SERVER_NAME=$2
export SERVER_NAME
TIMEOUT=$3
export TIMEOUT
## I am checking the processes for a server from the $(ENV)
SERVER_STATE=`ps -elf|grep
${ENV)|grep"Server.Name=${SERVER_NAME}"|grep -v grep`
## If I dont do the ps in a separate variable it gives me an error in
the test statement saying "test arguement expected".
if test -n "$SERVER_STATE"
then
ERROR_FLAG=1
EXIT_STATUS=1
echo "Server already present..."
echo "Exiting ..."
## the exit below is only exiting out of the while do but not the
whole shell script. Since it didnt do it, I am setting the EXIT_FLAG
to 1 and checking it after the loop.
exit
else
EXIT_STATUS=2
fi
# this is just to test my exit_status
echo " here i am: $EXIT_STATUS "
done
)< ${SERVER_INPUT_LISTING}
echo " here i am: $EXIT_STATUS"
# now I check the status of $EXIT_STATUS from the loop above to find
out whether I need to continue or exit out of the script... but the
values for the $EXIT_STATUS seems to be lost outside the loop... It
shows that it does not have any value... and if I declare it globally
to be 0, it shows 0.
if [$EXIT_STATUS -eq 1]
then
exit
fi
I think you are right about my shell...
> 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.
Is there anyway to get around this problem of redirected stdin ?. I am
using a Tru64 machine with OSF1 version 5.1 sp3(patch kit 3). Is it a
problem with the shell itself?
Thanks,
- SK
"Chris F.A. Johnson" <c.f.a.johnson@rogers.com> wrote in message news:<bfsbdq$ij2io$2@ID-136730.news.uni-berlin.de>...
> 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.
> >
> > >
> > 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}
- Next message: Charles Demas: "Re: Q for Unix guru's"
- Previous message: Alan Connor: "Re: Q: how do I open xterm, run command, and continue manual input?"
- In reply to: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Next in thread: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Reply: Chris F.A. Johnson: "Re: Errors when reading a file in Bourne shell -- HELP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|