home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5342 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  1.5 KB

  1. Path: sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!odin!chet
  2. From: chet@odin.ins.cwru.edu (Chet Ramey)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Bourne shell functions; what of 'exit'?
  5. Date: 11 Jan 1993 19:00:35 GMT
  6. Organization: Case Western Reserve University, Cleveland OH (USA)
  7. Lines: 38
  8. Message-ID: <1isg4jINNn8t@usenet.INS.CWRU.Edu>
  9. References: <1993Jan11.165425.7692@oracle.pnl.gov>
  10. NNTP-Posting-Host: odin.ins.cwru.edu
  11.  
  12. In article <1993Jan11.165425.7692@oracle.pnl.gov> zt_taylor@pnl.gov writes:
  13. $ Bourne shell functions seem to be inconsistent in the way they handle an 'exit'
  14. $ statement.  For example, the following:
  15. $     func() {
  16. $         .
  17. $         .
  18. $         exit 1
  19. $     }
  20. $     func
  21. $ causes the whole shell script to exit, while this:
  22. $     func() {
  23. $         .
  24. $         .
  25. $         exit 1
  26. $     }
  27. $     junk=`func`
  28. $     echo $?
  29. $ doesn't.  At first I thought this meant func was executed in a subshell, but
  30. $ echoing $$ both places gives the same PID.  Is this context-sensitive treatment
  31. $ of 'exit' a feature?  Can it be counted on in portable scripts?
  32.  
  33. The command substitution is indeed carried out in a subshell (what Posix.2
  34. terms a `subshell environment').  $$ is the same in both shells.  This is
  35. traditional sh behavior and is specified in Posix.2, so I think it can be
  36. counted on for portable shell scripts.
  37.  
  38. Chet
  39. -- 
  40. ``The use of history as therapy means the corruption of history as history.''
  41.     -- Arthur Schlesinger
  42.  
  43. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  44.