tcsh simple if expression...

tcsh simple if expression...

Post by Georg » Fri, 28 Jan 2005 11:20:47



Dear All,

I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
to work?

#!/usr/bin/tcsh
if ($?LIBPATH)  then
echo LIBPATH not set
endif

I've tried so may variations, like

if ( ${?LIBPATH} == '0' ) then ....

and I always get "if: Expression Syntax"

I got the if statement to work on the command line, just not in a file.

Any clues? I'm at wits end (clearly they are rather dim to begin with)
-g

 
 
 

tcsh simple if expression...

Post by Ed Morto » Fri, 28 Jan 2005 11:30:55



> Dear All,

> I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
> to work?
<snip>
> Any clues? I'm at wits end (clearly they are rather dim to begin with)
> -g

It's not you. See question 19 in the FAQ
(http://home.comcast.net/~j.p.h/cus-faq.html#S).

        Ed.

 
 
 

tcsh simple if expression...

Post by Barry Margoli » Fri, 28 Jan 2005 12:00:13




> Dear All,

> I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
> to work?

> #!/usr/bin/tcsh
> if ($?LIBPATH)  then
> echo LIBPATH not set
> endif

I have tcsh 6.12 on OS X 10.3.7 and it works fine for me (after changing
#!/usr/bin/tcsh to #!/bin/tcsh).

Try putting whitespace between the parentheses and $?LIBPATH.  
Traditional csh had some problems parsing some of these commands without
whitespace, and I thought tcsh resolved most of them, but maybe not.

Note that you have the test backwards.  You'll print "LIBPATH not set"
when the variable *is* set.  You should change it to:

if (! $?LIBPATH ) then

--

Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

 
 
 

tcsh simple if expression...

Post by Barry Margoli » Fri, 28 Jan 2005 12:14:56





> > Dear All,

> > I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
> > to work?
> <snip>
> > Any clues? I'm at wits end (clearly they are rather dim to begin with)
> > -g

> It's not you. See question 19 in the FAQ
> (http://home.comcast.net/~j.p.h/cus-faq.html#S).

That doesn't answer the question, it just avoids the problem.

I agree that it's a bad idea to write scripts in csh, but there are
times when it's unavoidable, such as the .login and .cshrc scripts for
users who want to use csh as their interactive shells.

--

Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

 
 
 

tcsh simple if expression...

Post by Ed Morto » Fri, 28 Jan 2005 15:13:49






>>>Dear All,

>>>I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
>>>to work?

>><snip>

>>>Any clues? I'm at wits end (clearly they are rather dim to begin with)
>>>-g

>>It's not you. See question 19 in the FAQ
>>(http://home.comcast.net/~j.p.h/cus-faq.html#S).

> That doesn't answer the question, it just avoids the problem.

That's right. I'd rather help someone avoid a problem than solve their
current one knowing they'll be hitting more in future.

Quote:> I agree that it's a bad idea to write scripts in csh, but there are
> times when it's unavoidable, such as the .login and .cshrc scripts for
> users who want to use csh as their interactive shells.

That's true, but IMHO we should give the OP no real option but to mull
over the information and then, if appropriate, tell us they can't avoid
it rather than providing them a solution which they'll almost certainly
just take and implement (ignoring any suggestions to the contrary) and
so go even further down the path of being unable to change direction it
that were possible.

        Ed.

 
 
 

tcsh simple if expression...

Post by Bruce Barnet » Fri, 28 Jan 2005 20:44:39



> #!/usr/bin/tcsh
> if ($?LIBPATH)  then
> echo LIBPATH not set
> endif

Barry's right. But I would add two things

#!/usr/bin/tcsh -f
if ( ! $?LIBPATH )  then
        echo LIBPATH not set
endif

[1] a space between the ( and !
[2] the -f after tcsh - in case your .cshrc has something funky

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

tcsh simple if expression...

Post by Billy Patto » Fri, 28 Jan 2005 23:30:23


I tried this and it works on linux and solaris8
#!/bin/tcsh

#!/usr/bin/tcsh  tcsh not installed at this location on linux box
if ! ( $?LIBPATH )  then
   printf "LIBPATH not set\n";
endif


> Dear All,

> I'm using tcsh 6.11 on AIX 5.2.  Why can't I get a simple if expression
> to work?

> #!/usr/bin/tcsh
> if ($?LIBPATH)  then
> echo LIBPATH not set
> endif

> I've tried so may variations, like

> if ( ${?LIBPATH} == '0' ) then ....

> and I always get "if: Expression Syntax"

> I got the if statement to work on the command line, just not in a file.

> Any clues? I'm at wits end (clearly they are rather dim to begin with)
> -g

    ___  _ ____       ___       __  __
   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
            /___/
Texas Instruments ASIC Circuit Design Methodology Group