Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!jtsv16!edward From: edward@jts.com (Edward Tsia) Newsgroups: comp.unix.shell Subject: Exit in Bourne Shell Message-ID: <1990Sep14.202920.10360@jts.com> Date: 14 Sep 90 20:29:20 GMT Distribution: tor Organization: JTS Computer Systems Ltd. Lines: 48 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: stop () { exit 0 } while read a do stop echo $a done < junk.data echo hello2 The accompanying junk.data file could be: hello hello ... hello 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. --