Thread View: comp.unix.shell
1 messages
1 total messages
Started by Edward Tsia
Fri, 14 Sep 1990 20:29
Exit in Bourne Shell
Author: Edward Tsia
Date: Fri, 14 Sep 1990 20:29
Date: Fri, 14 Sep 1990 20:29
48 lines
1639 bytes
1639 bytes
I am currently having problems understanding why a command inside a while-do-
done loop calling a function which calls exit does not exit the shell, but only
breaks from the while loop.
I have found this to be the case only for a while loop which accepts input from
a redirected file; if standard input (keyboard) is used, exit works as
anticipated. The following is an example:
<beginning of script>
stop () {
exit 0
}
while read a
do
stop
echo $a
done < junk.data
echo hello2
<end of script>
The accompanying junk.data file could be:
<beginning of junk.data>
hello
hello
...
hello
<end of junk.data>
As stated above, this script, upon execution, would echo 'hello2', although it
obviously should call function stop which in turn should terminate the shell.
However, if the redirection from junk.data is removed and the input is
received from keyboard, the exit call does terminate the shell.
I wonder whether this behaviour is caused by the fact that a subshell is
generated when the while-do-done loop is started and the 'exit' only causes
this child process to terminate, thus returning to its parent to continue
processing.
I would appreciate any comments which may shed any light on this matter.
I'd like to thank you in advance for your help.
Ed.
--
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads