[comp.unix.questions] csh weirdness

mbt@bridge2.3Com.Com (Brad Turner) (02/09/89)

Something strange happened to me today while renameing some files
and I can't explain it so maybe some of you can. Here goes

I had 10 files named zoo-1 zoo-2 zoo-3 .... zoo-08 zoo-09 zoo-10
and I wanted to rename them so that a shell expansion of zoo* would
have them aplhabetized so I did the following:

% foreach i ( 1 2 3 4 5 6 7 8 9 )
> mv zoo-$i zoo-0$i
> end;ls
> end

When the loop was executed it did the first mv then an ls of my current
directory, then the second mv and another ls..... after the last ls
I got the following "end: Not in while/foreach." I was under the impression
that above would execute the loop, then execute an ls. I had no intention
of putting in the last end statement, but when the shell gave me the
secondary prompt after I had already entered "end;ls" If figured what the
hell and entered the second end. What caused this?

-brad-

-- 
v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v
Brad Turner	1330 Ashleybrook Ln.	(919) 768-2097	| I speak for myself
3Com Corp.	Winston-Salem, NC 27103 mbt@bridge2	| NOT for my employer.

maart@cs.vu.nl (Maarten Litmaath) (02/10/89)

mbt@bridge2.3Com.Com (Brad Turner) writes:
\% foreach i ( 1 2 3 4 5 6 7 8 9 )
\> mv zoo-$i zoo-0$i
\> end;ls
\> end

\... I had no intention
\of putting in the last end statement, but when the shell gave me the
\secondary prompt after I had already entered "end;ls" I figured what the
\hell and entered the second end. What caused this?

Welcome to csh! It's just the way csh works: confusing syntax, buggy parser.
Beware if you want to use anything more difficult than:

	alias	ll	ls -la
	set	history = 20

The `end' statement must either appear alone on a line, or followed by a
semicolon PRECEDED BY WHITESPACE! Everything after the `;' (on the same line)
is PART OF THE LOOP!
Now go home, switch on your turntable and put on some record called `Crying'.
-- 
 "I love it                            |Maarten Litmaath @ VU Amsterdam:
          when a plan comes together." |maart@cs.vu.nl, mcvax!botter!maart