home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3515 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  2.8 KB

  1. Xref: sparky comp.unix.shell:3515 comp.sys.hp:9407
  2. Path: sparky!uunet!munnari.oz.au!mtiame!marvin!tony
  3. From: tony@marvin.jpl.oz (Tony Sanderson)
  4. Newsgroups: comp.unix.shell,comp.sys.hp
  5. Subject: ksh bk-gnd behaviour
  6. Message-ID: <891@marvin.jpl.oz>
  7. Date: 19 Aug 92 07:21:13 GMT
  8. Reply-To: tony@marvin.jpl.oz (Tony Sanderson)
  9. Distribution: world
  10. Organization: Boral Elevators, Melbourne
  11. Lines: 64
  12.  
  13.  
  14.  With ksh (HP-UX on a new '720), I find that scripts which successfully
  15. used either the "[ -t 0 ]" or "tty" commands on our old system to detect
  16. that the script has been backgrounded no longer work.  I'm told (by HP)
  17. that this is a result of the job control feature (which is absent in the
  18. ksh on our older machines),  causing stdin to remain attached to the user
  19. terminal when a script is backgrounded.  Suggestion was to insert a !sh
  20. command at the top of every script to ensure processing by the bourne
  21. shell.  I suppose I could do that,  but it seems like a pretty pathetic
  22. "solution" to me (esp as we don't use job control around here anyway!).
  23.  
  24.  They suggested I read "The Korn Shell" by Dave Korn - I've just flicked
  25. thru that for an hour or so,  but I'm none the wiser!  Have I just found
  26. a major deficiency or limitation of ksh,  or is this an HP implementation
  27. quirk? I find it difficult to believe that there's no simple way for a
  28. script to tell that it's running in the background! (Incidentally,  both
  29. tests work fine where the script gets installed in a pipe.)
  30.  
  31.  A test script (for anyone who may be interested) using the aforementioned
  32. commands is as follows:
  33.  
  34. ----------------------------- snip 'ere ---------------------------------
  35. #  Test for foreground v/s background execution of this script, and its
  36. #  ability to detect same.
  37. #  To simplify things (with stdout blocking or whatever),  writes result
  38. #  to file "yy":
  39.  
  40. echo 'Result via "test -t 0", method (a): \c' > yy
  41.  
  42. if [ -t 0 ]
  43. then
  44.         echo "Terminal attached" >> yy
  45. else
  46.         echo "Terminal not attached" >> yy
  47. fi
  48.  
  49. echo 'Result via output of tty command, method (b): \c' >> yy
  50.  
  51. if [ "`tty`" = "not a tty" ]
  52. then
  53.         echo "Terminal not attached" >> yy
  54. else
  55.         echo "Terminal attached" >> yy
  56. fi
  57.  
  58. # End
  59. ----------------------------- and 'ere too ------------------------------
  60.  
  61. Any suggestions?
  62.  
  63. PS: had a look thru the FAQ's for ...unix.shell about a month ago and saw
  64. no reference to it there,  hence the post.
  65.  
  66. PS 2: Just in case anyone reading this did answer another recent post re
  67. methods for an efficient 16 bit integer divide-by-5 method (which I'm
  68. looking for), we just lost the last 2 weeks news around here as a result
  69. a disc crash - so could u re-post!
  70.  
  71. -----------------------------------------------------------------------------
  72.  
  73. Tony Sanderson        Boral Elevators, Melbourne, Australia
  74.             e-mail tony@marvin.jpl.oz.au
  75.  
  76. -----------------------------------------------------------------------------
  77.