Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jan 2002 02:01:14 -0500
From:      Brian T.Schellenberger <bts@babbleon.org>
To:        Cliff Sarginson <cliff@raggedclown.net>, freebsd-questions@FreeBSD.ORG
Subject:   Re: shells confusion
Message-ID:  <20020126070114.C8FD93FE5@i8k.babbleon.org>
In-Reply-To: <20020126035658.GC1290@raggedclown.net>
References:  <20020126020430.P175-100000@BLAST> <20020126035658.GC1290@raggedclown.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 25 January 2002 10:56 pm, Cliff Sarginson wrote:
> On Sat, Jan 26, 2002 at 02:18:16AM +0200, Bernie wrote:
> > hi,
> >
> > i'm planning to learn shell programming but i'm not sure
> > on which one to choose...
> >
> > i've been reading in the 'FreeBSD unleashed' that people
> > wanting to do shell programming should stay away from
> > c-shell as it's realy good for interactive, but very bad
> > for scripts. is this true?
>
> Yes and Yes.

I would not agree with this at all.  I find csh much more readable/sensible 
than /bin/sh for interactive use.  Spaces don't matter; if statements are 
vastly more readable, etc.

Now for really complex "shell" programming I use perl, but C shell is, IMHO, 
a lot easier to write and read than /bin/sh.

There *is* one severe problem with csh that I know of: the quoting rules are 
just plain broken; if you get into nested quotes things get screwy quickly.  
I work around this with

set Q = "'"
set QQ = '"'
set $S = '$'

at the top of my scripts, but I freely admit that it is completely stupid 
that I should have to do so, but writing

if ($a > 4) then
     echo "$a is greater than 4"
endif

vs.

if [[eval $a > 4]];;
    echo "$a just tell me that's more readable.  I dare you."
fi

(or whatever--the syntax is inexact) it just seems to be to be no contest: 
csh wins, hands-down.

Plus the convenience of

if ($a =~ foo*)

vs. (as far as I can tell) having to do a switch just for string tests -- 
again, csh is the scripting shell for me.

EXCEPT that on non-BSD systems, csh isn't necessarily always avaialble.

Other than that, when push comes to shove, this is more a matter of personal 
opinion than any inherent superiority of one shell over another.

(Well, bash or zsh, which postdate /bin/sh and csh might be better and of 
course tcsh is better than original csh . . . but /bin/sh is really terrible 
for scripting if you ask me, never mind that it's widely used.)

> > also, looking into the scripts in /etc, i see a line on the
> > top saying 'bin/sh'. so are they all written in 'sh' and
> > not csh ? if so, why freebsd comes with csh as default?
>
> /bin/sh is the Unix common denominator of shells, so scripts
> get written in it. They are not written in csh, because as
> stated csh script is unusable for all practical purposes.

unusable???????  What on earch are you talking about?

I have many dozens of quite usable csh scripts.  And they are readable, too.

>
> You will be opening up another war here on the subject
> of which shell should be the default user/root shell.
> You may notice that "root" has two entries on the system,
> one as "root" with csh as it's shell, and one as "toor"
> with sh as it's shell.
>
> By the way, csh = tcsh on FreeBSD, I don't know if there
> is a "pure" csh around anymore. The huge difference between
> csh as was, and tcsh, being that tcsh is usable (ducks).

The main difference is the interactive history.  Lots of other bells & 
whistles, but csh was usable, too.  A huge, huge improvement for both 
interactive and scripted use over the original /bin/sh.


> In summary, *not* the csh for scripts.
> Learn sh for scripts.

I agree that you might have to (unfortunately) learn a mininum of sh for 
scripts, because the vast majority of scripts are written in it, but it's 
definately a matter of opinion whether they *should* be written in it.

> Use bash or tcsh for your day to day interactive use.
>
> I think most people will give you more or less the same
> advice, the choice of tcsh or bash will mostly depend on
> their personal Unix backgrounds as much as anything else.

-- 
Brian T. Schellenberger . . . . . . .   bts@wnt.sas.com (work)
Brian, the man from Babble-On . . . .   bts@babbleon.org (personal)
                                        http://www.babbleon.org

-------> Free Dmitry Sklyarov!  (let him go home)  <-----------

http://www.eff.org                 http://www.programming-freedom.org 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020126070114.C8FD93FE5>