Re: [dev] Shell vs C where is the border?

From: Chris Down <chris_AT_chrisdown.name>
Date: Tue, 11 Mar 2014 03:56:14 +0800

Szymon Olewniczak writes:
> But having so many individual programs is more harder to use that just
> one (we need to run more commands), so reasonable would be to combine
> all this commands to one script which would do all this work
> automaticaly. So what solution would be better in your opinion? When
> we should use shell scripts and when write new C programs to achieve our
> goals?

Most shells typically have a mixture of the bad points of the "new"
languages, and the more traditional, "old" languages:

- Not expressive
- Interpreted
- No typing system (or rudimentary)
- Extremely rudimentary programming constructs

Use shell scripts to piece together tools for common tasks. They should
really only be used in a few cases:

- Acting as a wrapper for rudimentary IPC
- Manipulating file hierarchies
- Manipulating files and streams (not the shell, but sed/awk are
  typically available)
- Launching other programs

These are things that are well implemented in the shell, and don't
suffer from many of the caveats that permeate most modern shells. Almost
all other use of the shell, in my opinion, is wrong. Use another
programming language for anything that is even remotely invested.

Things which look correct are often wrong for subtle, bug-inducing
reasons (often compatibility reasons). The POSIX shell in particular has
some insane default actions, some of which cannot be fixed in a POSIX
shell alone.

Think hard before you use a (POSIX-y) shell script to do your bidding.

Received on Mon Mar 10 2014 - 20:56:14 CET

This archive was generated by hypermail 2.3.0 : Mon Mar 10 2014 - 21:00:06 CET