home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!odin!chet
- From: chet@odin.ins.cwru.edu (Chet Ramey)
- Newsgroups: comp.unix.shell
- Subject: Re: Bourne shell functions; what of 'exit'?
- Date: 11 Jan 1993 19:00:35 GMT
- Organization: Case Western Reserve University, Cleveland OH (USA)
- Lines: 38
- Message-ID: <1isg4jINNn8t@usenet.INS.CWRU.Edu>
- References: <1993Jan11.165425.7692@oracle.pnl.gov>
- NNTP-Posting-Host: odin.ins.cwru.edu
-
- In article <1993Jan11.165425.7692@oracle.pnl.gov> zt_taylor@pnl.gov writes:
- $ Bourne shell functions seem to be inconsistent in the way they handle an 'exit'
- $ statement. For example, the following:
- $
- $ func() {
- $ .
- $ .
- $ exit 1
- $ }
- $
- $ func
- $
- $ causes the whole shell script to exit, while this:
- $
- $ func() {
- $ .
- $ .
- $ exit 1
- $ }
- $
- $ junk=`func`
- $ echo $?
- $
- $ doesn't. At first I thought this meant func was executed in a subshell, but
- $ echoing $$ both places gives the same PID. Is this context-sensitive treatment
- $ of 'exit' a feature? Can it be counted on in portable scripts?
-
- The command substitution is indeed carried out in a subshell (what Posix.2
- terms a `subshell environment'). $$ is the same in both shells. This is
- traditional sh behavior and is specified in Posix.2, so I think it can be
- counted on for portable shell scripts.
-
- Chet
- --
- ``The use of history as therapy means the corruption of history as history.''
- -- Arthur Schlesinger
-
- Chet Ramey, Case Western Reserve University Internet: chet@po.CWRU.Edu
-