home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:3734 comp.unix.questions:10610
- Path: sparky!uunet!infoserv!steiny!root
- From: root@steiny.com (Admin)
- Newsgroups: comp.unix.shell,comp.unix.questions
- Subject: Re: Shell Scripts vs. C programs
- Keywords: shell script, C
- Message-ID: <121@steiny.com>
- Date: 1 Sep 92 15:21:43 GMT
- References: <1992Aug31.211738.1909@tjhsst.vak12ed.edu> <119@steiny.com> <1992Sep1.044434.7193@news.acns.nwu.edu>
- Organization: Don Steiny Software
- Lines: 65
-
- navarra@casbah.acns.nwu.edu (John Navarra) writes:
-
- >In article <119@steiny.com> steiny@steiny.com (Don Steiny) writes:
- >>nurban@tjhsst 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!
-
- The shell may be, but the utilities that the shell calls in order
- to operate are not, thus, shell scripts are non-portable. Believe me,
- I had to write a distribution package for software that runs on many machines.
- I eventually had to re-write it in C because the shell was so non-portable.
- Many other posters to this thread have also had this experience. The
- only reason that you think that is because you have not had much experience
- trying to port shell scripts.
-
- >> there is no error checking,
-
- > There isn't? What does this mean? You write error checking
- >into the shell program just like you write it into C program.
-
- If you accidently misspell a variable name, then the shell simply
- takes it as a decleration. In the 14 years I have been working
- professionally with UNIX I have witnessed numerous attempts to write
- substantial applications in the shell and they have all failed.
-
- >>and they have many other problems.
- > And translating your C code using compiler X to OS Y is any
- >easier? Perhaps you are thinking of Csh? Then, yeah, you suck.
-
- Are you saying that the shell runs in more environments than
- C compilers?
-
- >>For very short programs shell
- >>might be better, but in general C is better for many reasons.
-
- > Even for long programs, shell scripts can be better. Yes, they
- >will run slower but if you can saves days, weeks, or months writing
- >the shell script, which is better then?
-
- Why would that be, if you did not know C? Why not use perl? It
- is supported on more machines than the shell, it has error checking, it
- is portable, and it so much better than the shell it boggles the mind.
-
-
- > It generally takes much longer
- >to write the same code in C as it does in a shell, perl, or awk. And,
- >once you have that script written, it is generally trivial to port it
- >to another machine -- especially if that machine runs the SAME SHELL!
-
- And has the exact same semantics for all of the commands. In other
- words, you are not trying to port a shell script from AT&T to BSD.
-
- Besides, if you really know C it is as fast to write many things
- as the shell. For text processing, use perl. The shell stinks as
- a programming language for anything but short interactive programs.
-
- -don
-