Re: what is difference in C prog and shell prog?

From: Josef Moellers (josef.moellers_at_fujitsu-siemens.com)
Date: 08/24/05


Date: Wed, 24 Aug 2005 09:10:26 +0200

rahul8143@gmail.com wrote:
> hello,
> i want to know what is difference between C prog. and shell
> prog.? which is richer in functionality, speed on linux OS?
> regards,

A C program is written in C, then compiled into machine language and
then run.
A shell script (they are not usually referred to as programs) is
interpreted by the shell every time it is run, even each statement is
interpreted every time it is seen during interpretation of the script as
a whole (other interpreters might keep some intermediate form of
statements already handled to speed up execution).

The functionality of a C program is limited only by the functions
provided by the underlying operating system kernel (the remaining
functionality is provided by some libraries which are usually written in
C, too, so the use of these could be precluded by including the relevant
functions in your C program), while a shell script actually only adds
some flow control and some variable handling but for the rest has to
rely on the utilities available on the system.

Although a C program can be written to be highly portable, the compiled
program will run on only a certain class of machine (a program compiled
for an Intel CPU will not run on a PowerPC), sometimes even restricted
to a (certain flavour of) OS (a program compiled for Linux will
definitely not run on Windows) while shell scripts will run on any
machine that has the shell and the commands used by the script.

 From a theoretic point of view, you could (probably) rewrite any C
program as a shell script (there is a theorem postulated by someone,
Alonso Church?, that claims this), but it would be quite clumsy and run
orders of magnitude slower.

-- 
Josef Möllers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


Relevant Pages

  • Re: /lib/ld-2.2.4.so
    ... "noexec" are hardly of any security value, and it is a great mistake to ... coming from shell users, ... needed to do it is excessive and functionality impact is pretty severe. ... Default Linux shells do not extensively support trust / access control. ...
    (Vuln-Dev)
  • Re: Dynamic Context Menu
    ... I wrote a small program to process some data files. ... I have been playing with the registry, ... functionality, but I can only do static menus. ... Shell Extensions ...
    (microsoft.public.vb.general.discussion)
  • Re: Dynamic Context Menu
    ... I wrote a small program to process some data files. ... functionality, but I can only do static menus. ... Shell Extensions ... Thanks Nobody, I'm studying the file and shell standards. ...
    (microsoft.public.vb.general.discussion)
  • Re: Sun OS Environment/Utilities Question
    ... took this functionality for granted, but never knew what made it possible. ... That's a function of your shell, ... If your default shell is csh, I recommend switching to tcsh. ...
    (comp.unix.shell)
  • Re: what is difference in C prog and shell prog?
    ... which is richer in functionality, ... > Everything that can be done in a shell script can also ... > will always outperform a shell script. ... but using a pneumatic hammer sometimes beats hammer ...
    (comp.os.linux.development.apps)