[comp.unix.questions] C shell script files

mturner@convexe.UUCP (01/14/88)

I was wondering if anyone knew of any good books that could help me to 
learn unix c shell script files.
---anything would be helpful
thanks
----Mike Turner

amos@taux01.UUCP (Amos Shapir) (01/19/88)

Better forget it! Use csh for interactive work, sh (or ksh) for command
files. The command interface of csh is horrible: you can't nest if's and
while's, keywords must be first on their line, you can't freely interchange
semicolons with new-lines, you can't pipe the output of while's, etc, etc.
-- 
	Amos Shapir			(My other cpu is a NS32532)
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel  Tel. +972 52 522261
amos%taux01@nsc.com  34 48 E / 32 10 N

lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) (01/19/88)

In article <448@taux01.UUCP> amos%taux01@nsc.com (Amos Shapir) writes:
>Better forget it! Use csh for interactive work, sh (or ksh) for command
>files. The command interface of csh is horrible: you can't nest if's and
>while's, keywords must be first on their line, you can't freely interchange
>semicolons with new-lines, you can't pipe the output of while's, etc, etc.

You are right that ksh is better than csh for command files, but it is
also excellent for interactive work.  I even think it is superior to csh
for interactive work.  The only thing that ksh can't do that csh can
(that I care about) is for aliases to manipulate their arguments.  Even
this can be gotten around by combining the alias with a function.  What
is csh so good at?
-- 
Larry Cipriani, AT&T Networks Systems (by day) Ohio State University (by night)
Domain: lvc@tut.cis.ohio-state.edu
Path: ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc (yes its right)

mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) (01/20/88)

From article <4795@tut.cis.ohio-state.edu>, by lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani):
> for interactive work.  The only thing that ksh can't do that csh can
> (that I care about) is for aliases to manipulate their arguments.  Even
> this can be gotten around by combining the alias with a function.  What
> is csh so good at?

csh history editing isn't user-friendly, but I usually find it more
convenient than using emacs-style commands (which, like ksh, tcsh has).
csh is also good at not costing anything to have on 4bsd-ish un*xes B').

(this is for the line counter)

Mike Khaw
-- 
internet:  mkhaw@teknowledge-vaxc.arpa
usenet:	   {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge-vaxc.arpa
USnail:	   Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

milgr@brandeis.csnet (Marc Milgram) (01/20/88)

Subject: C shell script files

 Amos Shapir <amos@taux01.uucp> writes:
>Better forget it! Use csh for interactive work, sh (or ksh) for command
>files. The command interface of csh is horrible: you can't nest if's and
>while's,                                         ^^^^^^^^^^^^^^^^^^^^^^^
 ^^^^^^^
Yes you can - though it is kind of ugly
> keywords must be first on their line,
[;^][ \t<label>]*<keyword> ... is the regular expression representing
where keywords can go.  Is this so bad?  Should they be allowed in
other places?

> you can't freely interchange
>semicolons with new-lines, 
You have a point

>you can't pipe the output of while's, etc, etc.
Try enclosing the whiles in ()'s.

I have written shell scripts in both sh and csh.  Currently, I can
write scripts faster in the csh because I use most of the features of
the csh every day, and I almost never use sh.

	-Marc Milgram
	(milgr@brandeis.edu)

howard@COS.COM (Howard C. Berkowitz) (01/20/88)

In article <65200004@convexe>, mturner@convexe.UUCP writes:
> I was wondering if anyone knew of any good books that could help me to 
> learn unix c shell script files.


I recently bought _The UNIX C Shell Field Guide_ by Gail & Paul
Anderson (Prentice Hall); $27.95 at B. Dalton.  I am extremely
pleased with it, as it pulled together a number of things I knew
intuitively (i.e., as a developer under SunOS without any formal
UNIX training).

Not all the scripts ran unmodified on our Sun system, but not
much work was needed.  For some reason, perhaps only my own
visual perception, I found the book much more useful when I 
highlighted the "meat" in various paragraphs; I don't usually
find this necessary.  Perhaps this shows the book as more
of a tutorial than a "conversion guide" for experienced programmers,
which may be the authors' goal.
-- 
-- howard(Howard C. Berkowitz) @cos.com
 {uunet,  decuac, sun!sundc, hadron, hqda-ai}!cos!howard
(703) 883-2812 [ofc] (703) 998-5017 [home]
DISCLAIMER:  I explicitly identify COS official positions.

lm@arizona.edu (Larry McVoy) (01/21/88)

In article <11333@brl-adm.ARPA> milgr@brandeis.csnet (Marc Milgram) writes:
>Subject: C shell script files
>I have written shell scripts in both sh and csh.  Currently, I can
>write scripts faster in the csh because I use most of the features of
>the csh every day, and I almost never use sh.

Remember this when you start suggesting that csh is the way to go: 

    A sh(1) script is portable to every unix box out there.  
    Csh scripts are not.

-- 
Larry McVoy	lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm
		Use the force - read the source.

PAAAAAR%CALSTATE.BITNET@CUNYVM.CUNY.EDU (01/22/88)

Marc Milgram
(milgr@brandeis.edu)
writes
>Currently, I can
>write scripts faster in the csh because I use most of the features of
>the csh every day, and I almost never use sh.

I am the reverse of this - I use 'sh' all the time and write scripts in'sh'
as a result.

I use Mac as a vt100 terminal (Scott Watson's Red Ryder does the emulation)
with a mouse that lets me take any command or output and make a copy,
screen edit it, send it again, even run it thru a Greo-Wc desk Accessory...

My question - it is a historical fluke that I use 'sh' rather than 'csh'.
Given that I have my local versions of aliases and history what can I gain
from switching to 'csh'?

Note - 'ksh' we don't have in PDP land.
Dick Botting,
PAAAAAR@CCS.CSUSCC.CALSTATE(doc-dick)
paaaaar@calstate.bitnet
PAAAAAR%CALSTATE.BITNET@CUNYVM.CUNY.EDU
Dept Comp Sci., Cal State U, San Bernardino, CA 92407
Disclaimer: I am an only an egg

uppal@hpindda.HP.COM (Sanjay Uppal) (01/23/88)

Mike,
If despite all the advice to the contrary, you do want
to use csh in script files, I recommend
"The Unix C Shell Field Guide" by Gail Anderson & Paul Anderson,
Prentice Hall $27.95.

Sanjay Uppal (NN9T, VU2SMT)	phone:	(408) 447-3864
Hewlett-Packard (IND)		uucp: ...!hplabs!hpda!uppal
NS/800			 	arpa: uppal%hpda@hplabs.hp.com

marki@hpiacla.HP.COM (Mark Ikemoto) (01/23/88)

> I was wondering if anyone knew of any good books that could help me to 
> learn unix c shell script files.
> ---anything would be helpful
> thanks
> ----Mike Turner

Talk about basenotes drift!!  4 responses in back of me and none of
them address Mike's question.

I use "The Unix C Shell Field Guide" by Gail and Paul Anderson (Prentice-
Hall), 1986.  Truthfully, this was given to me by my boss so I've never
actively looked for a "good" reference book.  I've thumbed through The
Field Guide; used some parts more than others.  It seems fairly complete
(and has a beautiful photo of a seashell on the front of it).

Actually, I use Bourne for my scripts.  It's faster and has more features
than C-Shell.


Mark

mturner@convexe.UUCP (01/25/88)

Thanks for all the help finding good c shell script books.
----Mike Turner

mic@hpesrgd.HP.COM (Marc Clarke) (01/28/88)

"Unix Shell Programming", by Stphen G. Kochan and Patrick H. Wood, Hayden
Books, 1985, isbn 0-8104-6309-1, has an excellent chapter on the C shell.
However, I heartily reccomend you make the jump to light speed and pick up
Ksh.

amos@taux01.UUCP (Amos Shapir) (01/29/88)

In article <170@chessene.UUCP> hermit@chessene.UUCP (Mark Buda) writes:
>Our sh(1) hangs on long shell scripts. My kingdom for a PD shell, or an sh to
>csh translator!!!!

This is a very old bug, due to the strange way in which sh manages its
memory allocation. The fix (or rather a patch that will prevent the bug
from hurting) is to comment out the body of the routine stakchk() in stak.c
(it's just 3 lines).

-- 
	Amos Shapir			(My other cpu is a NS32532)
National Semiconductor (Israel)
6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel  Tel. +972 52 522261
amos%taux01@nsc.com  34 48 E / 32 10 N