Re: problem with exit while using nohup
- From: Mark Wooding <mdw@xxxxxxxxxxxxxxxx>
- Date: Tue, 20 Jan 2009 23:04:52 +0000
Sumir <sumirmehta@xxxxxxxxx> writes:
I am kinda confused with this, am not sure what is happening
i have a script say test.sh
----------
cat myfile | while read line
do
exit 2
done
echo "out of loop"
-----------
as it is evident, the exit should cause the script to terminate ,hence
producing no output for the script.
now when i run the script as "./test.sh", the behaviour is as
expected.
but when i run it with nohup as "nohup ./test.sh &", the "out of loop"
statement appears in the output, indicating that the exit just gets it
outside the loop but does not exit the program.
How odd. None of the shells I've tried have exited the shell from
inside the loop.
What's happening is that the `while' loop is being run in a subprocess;
so `exit' is exiting that subshell. You can verify this by printing
`$?' in the final `echo'. The POSIX spec allows this behaviour (IEEE
1003.1 Shell and Utilities 2.12):
: Additionally, each command of a multi-command pipeline is in a
: subshell environment; as an extension, however, any or all commands in
: a pipeline may be executed in the current environment.
any ideas on this ?
My guess is that you're using different shells in the two cases.
-- [mdw]
.
- Follow-Ups:
- Re: problem with exit while using nohup
- From: Andre Majorel
- Re: problem with exit while using nohup
- References:
- problem with exit while using nohup
- From: Sumir
- problem with exit while using nohup
- Prev by Date: Machine data
- Next by Date: Re: Remove a chess game from a file.
- Previous by thread: problem with exit while using nohup
- Next by thread: Re: problem with exit while using nohup
- Index(es):
Relevant Pages
|