home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / next / bugs / 48 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  1.8 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool.mu.edu!agate!usenet.ins.cwru.edu!odin!chet
  2. From: chet@odin.ins.cwru.edu (Chet Ramey)
  3. Newsgroups: comp.sys.next.bugs
  4. Subject: Re: /bin/sh $# bug with nested functions
  5. Date: 12 Jan 1993 18:35:11 GMT
  6. Organization: Case Western Reserve University, Cleveland OH (USA)
  7. Lines: 43
  8. Message-ID: <1iv30vINNe8q@usenet.INS.CWRU.Edu>
  9. References: <1993Jan12.160259.7994@bernina.ethz.ch>
  10. NNTP-Posting-Host: odin.ins.cwru.edu
  11.  
  12. In article <1993Jan12.160259.7994@bernina.ethz.ch> waldvoge@nessie.cs.id.ethz.ch (Marcel Waldvogel) writes:
  13. $ Another nasty bug (which prevents me using 'shql' for now):
  14. $     #!/bin/sh
  15. $     nested_func(){
  16. $             echo "inside: $#"
  17. $     }
  18. $     func(){
  19. $             echo "before: $#"
  20. $             nested_func 6 7 8
  21. $             echo "after : $#"
  22. $     }
  23. $     func 1 2 3 4 5
  24. $ gives the following output (on 2.1 and on 3.0):
  25. $     before: 5
  26. $     inside: 3
  27. $     after : 3
  28. $ Every other system I've tried returns
  29. $     before: 5
  30. $     inside: 3
  31. $     after : 5
  32. $ This is in accordance to what I expect from the behaviour of parameter passing.
  33.  
  34. The NeXT sh is based on the System V.2 sh (probably filtered through BRL,
  35. though I don't know for sure).  The V.2 sh had the behavior you've observed
  36. regarding $# and functions -- there was only a single array of arguments,
  37. and it was overwritten each time a function was called.  The V.3 sh changed
  38. that so that $# is saved and restored around each function call.  Posix.2
  39. has standardized the V.3 (and ksh, and bash, and the new BSD sh, and ...)
  40. behavior, but NeXT has not upgraded its version of sh. 
  41.  
  42. Chet
  43.  
  44. -- 
  45. ``The use of history as therapy means the corruption of history as history.''
  46.     -- Arthur Schlesinger
  47.  
  48. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  49.