Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 May 2000 08:29:18 -0600
From:      "Duke Normandin" <dnormandin@freewwweb.com>
To:        <cjclark@home.com>
Cc:        "'freebsd-questions@FreeBSD.org'" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: csh script syntax error
Message-ID:  <00ef01bfbb63$b3bb0d80$73dba7d1@dnormandinfreewwweb.com>

next in thread | raw e-mail | index | archive | help
On Wednesday, May 10, 2000 10:47 PM Crist J. Clark
<cjc@cc942873-a.ewndsr1.nj.home.com> wrote:


>On Wed, May 10, 2000 at 06:07:34PM -0600, Duke Normandin wrote:
>> I'm running 3.3R...
>> The following script ( a port from tcsh) fails with the error message
>> if: expression syntax error
>>
>> #!/bin/csh
>> #
>> if ( mv $* ~/tmp ) then
>>     echo "The files have been moved! To remove them "
>>     echo "use the 'purge' command "
>> else
>>     echo "Something's haywire! Files not moved. "
>> endif
>>
>> I can't figure this puppy out! Tia.....
>>
>> -duke
>
>First...
>
>DO NOT USE CSH FOR SCRIPTS. Use /bin/sh. (And I use tcsh for my
>interactive shells, wouldn't dream of writing scripts in it.)


I've been reading documents on the www about this issue -- something to
the effect that the C Shell is "evil". I'm not in a position to judge, although
the same could be said about C or Perl I suppose, *if* a person isn't inclined
to RTFM, and is a sloppy programmer. Of course, there is also the fact that
sh is "standard" across most *nix flavors (I think?) which fact should be
enough for me to drop csh.

>  #!/bin/sh
>  #
>  if mv $* ~/tmp; then
>      echo "The files have been moved! To remove them "
>      echo "use the 'purge' command "
>  else
>      echo "Something's haywire! Files not moved. "
>  fi


Thanks for the sh version!

>Second, if some evil force is compelling you to use csh, RTFM, csh(1),


Starting immediately, I've adopted a 48 hrs "cooling off" period for all
my posts to the FBsd/PHP/mySQL lists ;) Inevitably, I find the answer
on my own soon after I click on "send" -- as follows:

[quote]
Another use of commands is to use their return codes inside conditional expres-
sions.  For example, the -s option of the grep command stands for silent mode.
It causes grep to do its job without producing any output, but the return code
is then used.  You cannot see the return code, but you can use it if you sur-
round the command in curly braces:

     if ({grep -s junk $1}) then
           echo "We found junk in file $1"
     endif

Notice that if (`grep junk $1`) would not work because this would cause
grep's output to be substituted into the expression, but in silent mode, there
is no output.
[unquote]

Thanks for your help and advise!

-duke



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?00ef01bfbb63$b3bb0d80$73dba7d1>