Using shell commands versus C equivalents

David Wolfskill david at
Wed Jun 13 12:46:45 UTC 2007

On Tue, Jun 12, 2007 at 10:55:18PM -0700, Garrett Cooper wrote:
> Another simple question (I hope):
>    Is there any reason why shell commands should be used in place of a 
> C command (in this case chmod via vsystem instead of the chmod(2) 
> function)? It seems like the fork / exec would be more expensive with 
> the shell command, but any area where code could be optimized is more 
> than welcome I would think.

There often are reasons to prefer using shell commands to C.

There typically exist many tradeoffs involved in evaluating one over the
other, and "machine efficiency" is not always the highest goal.  (For
example, it may be better to reduce complexity in favor of having a
simpler structure that is easier for people to understand and maintain
with confidence that the changes they make have the desired results.
This is, of course, not to try to claim that shell scripts are
inherently easier to understand than C code; that would be a silly
stance to take.)

I commend to your attention Geoff Collyer and Henry Spencer's "C News"
(a successor to Rick Adams' "B News") implementation, a great deal of
which was written as shell scripts (ca. 1988 or so).

(Yes, I realize that that was almost 20 years ago, and that it
didn't involve FreeBSD per se.  Ignoring the lessons of history is
rather short-sighted and foolish:  despite using shell scripts for
so much of the "code," the machine I was then running went from
being extremely busy all the time to having a couple of bursts of
activity per day for about an hour each time -- with more news
flowing with C News vs. B News.)

David H. Wolfskill				david at
Anything and everything is a (potential) cat toy.

See for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url :

More information about the freebsd-hackers mailing list