home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:3766 comp.unix.questions:10641
- Newsgroups: comp.unix.shell,comp.unix.questions
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Shell Scripts vs. C programs
- Message-ID: <9224700.19887@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- 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>
- Date: Wed, 2 Sep 1992 14:42:42 GMT
- Lines: 49
-
- Kim Holburn <kim@csc.canberra.edu.au> writes:
-
- >In article <1992Sep1.044434.7193@news.acns.nwu.edu> John Navarra,
- >navarra@casbah.acns.nwu.edu writes:
- >>>>I've heard that if at all possible, code a program as a shell script
- >>>>rather than coding it in C. Can someone explain the rationale behind
- >>>>this philosophy?
- >>>
- >>> BZZZ - shell scripts are non-portable
- >>>
- >> Huh? Why are shell scripts non-portable? Unless you are using
- >>a non-standard shell, shell scripts are HIGHLY portable! Even if you
- >>aren't using a non-standard shell, say [ba|k|z|]sh, it is highly
- >>portable.
- >>For one, most [ba|k|z]sh scripts will run in sh and vice versa. And, if
- >>you need to, you can always get shell X and compile it on your machine.
- >>This is *usually* easier than rewriting C-code to accomodate your OS.
-
- >Not true. Having just had to port a set of programs that included C
- >programs and bourne-shell scripts from sunOS 4.1.x to sequent Dynix/ptx
- >(system V release 3.2). I can say that while the C took a day to port,
- >the shell scripts have taken over a week with another week maybe 2
- >likely. The C, because of conditional compilation is still a uniform set
- >of source. The scripts have diverged fairly rapidly and are not
- >interchangeable at all now.
-
- Huh? What happened to conditional execution?
- eg.
- if [ `arch` = "sgi" ]; then
- # SGI-specific code
- endif
-
- Another simple way of making shell scripts portable is to use header files,
- just like in C.
-
- . /usr/local/lib/standard_defines.sh # standard variable definitions
-
- if [ $SGI ]; then
- # SGI-specific code
- fi
-
- There is no justification for allowing the maintenance problem that will
- result from having multiple differing copies of each script for each machine.
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-