[net.unix] csh question

reece%nadc@sri-unix.UUCP (02/24/84)

I'm having trouble with nesting of csh "if-else-endif". In the following,

----------------------
#! /bin/csh
set x=1
if($x == 1) then
	set y=2
else
	if($y == 2) then
		echo "line 1"
	else
		echo "line 2"
	endif
	echo "shouldn't get here"
endif
echo "finished"
----------------------

when you run it, you get the "shouldn't get here" message printed out.
Does anyone know why? 

Jim Reece
REECE@NADC

jackm%ardc@sri-unix.UUCP (02/24/84)

From:      Jack Moskowitz (PAD) <jackm@ardc>

The format of the test command (that is what you are using) is:
if [ $x = 1 ]
then

jeff%aids-unix@sri-unix.UUCP (02/24/84)

From:  Jeff Dean <jeff@aids-unix>

Put a blank between the "if" and the open paren in the
nested if.

moss%brl-vld@sri-unix.UUCP (02/24/84)

From:      Gary S Moss ~Software Development Team~ <moss@brl-vld>

Jim --
	My guess is that you are fooling yourself with indentation and
white space causing an ambiguity in syntax.

if($x == 1) then    # Your code
	set y=2
else
	if($y == 2) then
		echo "line 1"
	else
		echo "line 2"
	endif
	echo "shouldn't get here"
endif
-------------------------
if($x == 1) then     # Equivalent
	set y=2
else if($y == 2) then
	echo "line 1"
else
	echo "line 2"
endif
echo "shouldn't get here"
endif

-- Moss.

moss%brl-vld@sri-unix.UUCP (02/24/84)

From:      Gary S Moss ~Software Development Team~ <moss@brl-vld>

Jack --
	You must not have noticed the subject field of Jim's
message, and the #!/bin/csh.  He was not using the test command
but evaluating a Cshell expression.

-- Moss.

lcc.bob%ucla-locus@sri-unix.UUCP (02/25/84)

From:            Bob English <lcc.bob@ucla-locus>

"csh" messes up on nested "if" statements (at least in 4.1).  It's
really that simple.  "if ... fi" is a bourne shell construction, and,
while aesthetically more satisfying, meaningless to the poor C-shell.
Furthermore, "csh" does its own expression testing; the program
"test is not being called...not even through its "[" alias.

I'm afraid you'll have to find a different way to do the test (or
fix "csh").

--bob--

woods@hao.UUCP (Greg Woods) (02/28/84)

  The problem is, there's a bug in your shell. On our machines, it does
not print the "shouldn't get here" line when I run that script.

	       GREG
-- 
{ucbvax!hplabs | allegra!nbires | decvax!stcvax | harpo!seismo | ihnp4!stcvax}
       		        !hao!woods

eric@burdvax.UUCP (Eric Marshall) (01/21/86)

	Why can't csh use stdio? Looking at the csh code, csh has its
own printf routine which prints using putchar, instead of putc, which
is what stdio uses. What's the difference between the two? The infamous
doprnt routine is also different. The makefile for csh contains
a comment that an old doprnt needs to be used whose output we
can trap. What does that mean? Whats this all about?

Thanks in advance.


Eric Marshall
System Development Corporation, a Burroughs Company
P.O. Box 517
Paoli, PA. 19301
(215) 648-7223

USENET: sdcrdcf!burdvax!eric
        {sjuvax,ihnp4,akgua,cadre}psuvax1!burdvax!eric
ARPANET: PAYTON@BBNG

DZOEY@umd2.umd.edu (Joe) (05/08/86)

Hi, I'm trying to revamp my .login, and part of it is to check to see
which terminal type (if any) the system think I'm signing in on.

I implement this by a large switch statement.  It looks something like.

switch ($term)
case 'type1':
case 'type2':
    .
    .
    .
case 'typen:    <some appropriate action for types 1-n inclusive>
                breaksw

and then the appropriate code if it matches any one of those.  The problem
I'm running into is I get a
case: Too many labels
error.  What is the maximum number of labels I can have for a single action?
right now, I have about 20, but I could probably cut it down to 5 if I had to.

Any help would be appreciated.

                    Thanks,
                      Joe

HERMAN@UMD2.UMD.EDU

franklin@ut-sally.UUCP (Maurice T. Franklin) (05/12/86)

In article <673@brl-smoke.ARPA> DZOEY@umd2.umd.edu (Joe) writes:
>Hi, I'm trying to revamp my .login, and part of it is to check to see
>which terminal type (if any) the system think I'm signing in on.
>
>I implement this by a large switch statement.  It looks something like.
>
>switch ($term)
>case 'type1':
>case 'type2':
>    .
>    .
>    .
>case 'typen:    <some appropriate action for types 1-n inclusive>
>                breaksw
>
>and then the appropriate code if it matches any one of those.  The problem
>I'm running into is I get a
>case: Too many labels
>error.  What is the maximum number of labels I can have for a single action?
>right now, I have about 20, but I could probably cut it down to 5 if I had to.
>
>Any help would be appreciated.
>
>                    Thanks,
>                      Joe
>
>HERMAN@UMD2.UMD.EDU

There is a command, tset, that does all this for you.  You just tell it
what type of terminal to set up the in shell for a given login terminal
type.  Tset is a rather complex command, but the man page is pretty good.
Here is part of the man page for tset:
----
EXAMPLES
export TERM; TERM=`tset - -m '>1200:vt100' 2621`

export TERM; TERM=`tset -e -k^U -Q - -m 'switch<=1200:concept100' -m 'switch:?vt100' -m dialup:concept100 -m arpanet:dm2500`
----
and here is part of my .login:
----
# Set up terminal type and modes.
set termdefault = vt100
set noglob
eval `tset -s -n -e -k^U -m 'network:?$termdefault'  -m 'sun:sun' -m 'dialup:st'   -m 'unknown:?$termdefault'`
unset noglob
----
Hope this is of help to you, and anyone else who has trouble (like I have had)
getting the shell to recognize your terminal.

	"Any sufficiently advanced technology is indistinguishable from magic"
		- Arthur C. Clark 

				Maurice T. Franklin
        			CS Dept University of Texas at Austin
UUCP:    			{ihnp4,seismo,harvard,gatech}!ut-sally!franklin
ARPA Internet and CSNET:    	franklin@sally.utexas.edu
[Disclaimer: The University of Texas at Austin, the Computer Science Dept, nor 
just about anybody else, is to be held responsible for what I say here.]