home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3766 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  2.5 KB

  1. Xref: sparky comp.unix.shell:3766 comp.unix.questions:10641
  2. Newsgroups: comp.unix.shell,comp.unix.questions
  3. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  4. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  5. Subject: Re: Shell Scripts vs. C programs
  6. Message-ID: <9224700.19887@mulga.cs.mu.OZ.AU>
  7. Sender: news@cs.mu.OZ.AU
  8. Organization: Computer Science, University of Melbourne, Australia
  9. References: <1992Aug31.211738.1909@tjhsst.vak12ed.edu> <la5rr9INNac3@almaak.usc.edu> <1992Sep1.044434.7193@news.acns.nwu.edu> <1992Sep1.073956.27085@csc.canberra.edu.au>
  10. Date: Wed, 2 Sep 1992 14:42:42 GMT
  11. Lines: 49
  12.  
  13. Kim Holburn <kim@csc.canberra.edu.au> writes:
  14.  
  15. >In article <1992Sep1.044434.7193@news.acns.nwu.edu> John Navarra,
  16. >navarra@casbah.acns.nwu.edu writes:
  17. >>>>I've heard that if at all possible, code a program as a shell script
  18. >>>>rather than coding it in C.  Can someone explain the rationale behind
  19. >>>>this philosophy?
  20. >>>
  21. >>>    BZZZ - shell scripts are non-portable
  22. >>>
  23. >>    Huh? Why are shell scripts non-portable? Unless you are using
  24. >>a non-standard shell, shell scripts are HIGHLY portable! Even if you
  25. >>aren't using a non-standard shell, say [ba|k|z|]sh, it is highly
  26. >>portable.
  27. >>For one, most [ba|k|z]sh scripts will run in sh and vice versa. And, if
  28. >>you need to, you can always get shell X and compile it on your machine.
  29. >>This is *usually* easier than rewriting C-code to accomodate your OS.
  30.  
  31. >Not true. Having just had to port a set of programs that included C
  32. >programs and bourne-shell scripts from sunOS 4.1.x to sequent Dynix/ptx
  33. >(system V release 3.2). I can say that while the C took a day to port,
  34. >the shell scripts have taken over a week with another week maybe 2
  35. >likely. The C, because of conditional compilation is still a uniform set
  36. >of source. The scripts have diverged fairly rapidly and are not
  37. >interchangeable at all now. 
  38.  
  39. Huh? What happened to conditional execution?
  40. eg.
  41.     if [ `arch` = "sgi" ]; then
  42.         # SGI-specific code
  43.     endif
  44.  
  45. Another simple way of making shell scripts portable is to use header files,
  46. just like in C.
  47.  
  48.     . /usr/local/lib/standard_defines.sh    # standard variable definitions
  49.  
  50.     if [ $SGI ]; then    
  51.         # SGI-specific code 
  52.     fi
  53.  
  54. There is no justification for allowing the maintenance problem that will
  55. result from having multiple differing copies of each script for each machine.
  56.  
  57. -- 
  58. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  59. This .signature virus is a self-referential statement that is true - but 
  60. you will only be able to consistently believe it if you copy it to your own
  61. .signature file!
  62.