1752613 Members
4463 Online
108788 Solutions
New Discussion юеВ

If sentence ..

 
SOLVED
Go to solution
Oviwan
Honored Contributor

Re: If sentence ..

try this:

if ($bb = 1) then
echo "hola"
else
echo "adios"
endif
Patrick Wallek
Honored Contributor

Re: If sentence ..

CSH is a completely different beast from sh or ksh.

Your script should be:

if ( $bb == 1 ) then
echo "hola"
else
echo "adios"
endif


Note the differences.

1st line -- You needs space between the open and close parentheses and the expressions. Also you needed a '==' (2 equal signs together) and the 'then' needs to be on the first line.

The last line of the script has to be 'endif'.

# man csh

will give you a LOT of info on the C-shell.
Manuales
Super Advisor

Re: If sentence ..

Thanks Patrick !!

i've worked with ksh ..

do you know if with csh you can make functiions llike ksh? it means, with ksh there is a variable specially to redirect a path where there will be functions .. do you kwno if this exists to csh?

Thanks, Manuales.
James R. Ferguson
Acclaimed Contributor

Re: If sentence ..

Hi Manuales:

The 'csh' shell is far inferior to the Posix ('usr/bin/sh'), 'ksh', and 'bash' shells.

See here, for one discussion of why *not* to use 'csh':

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Beyond, that, on HP-UX, for the 'root' account, in '/etc/passwd', NEVER specify any shell other than '/sbin/sh'. To do so will render your server unusable.

The Posix shell lives in '/sbin/sh' as a staticly-linked binary. As such, everything it needs to run is available in single-user mode (when '/usr' isn't mounted). The Posix shell in '/usr/bin/sh' is for general users and uses dynamically linked libraries in '/usr'. Non-root users should specify this shell in preference to '/sbin/sh'.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: If sentence ..

I don't know that much about csh. I would advise you to read the man page if you must use csh.

I try to avoid it if at all possible. I much prefer the POSIX shell.
Manuales
Super Advisor

Re: If sentence ..

Hi !!
i have a problem,
running script manually is ok. but if i run it from cron i have an error:

/home/scripts/test.sh[21]: Syntax error at line 56 : `else' is
not matched.
why?

my script is:

#!/usr/bin/csh
set p_monit=/home/scripts/MONITORING
#--->12132005 This is to take correct name in script
cd /interface/Towers/exe/backup
set aa=`ls -l | grep earn | awk '{ print $NF }'`
set bb=`echo $aa | wc -w`
if ($bb == 1) then
mv $aa db.opo
chmod 775 db.opo
else
set mensaje=`cat $p_monit/mail_messages.txt | grep 01 | cut -d":" -f2`
echo $mensaje | mailx -s "01 ORANGE ALERT to Mexico" me@patito.com.mx
endif

Thanks, Manuales.

James R. Ferguson
Acclaimed Contributor

Re: If sentence ..

Hi Manuales:

The 'cron' environment is quite sparse, containing:

HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

That is, *any* variables that are usually in your profile or login file are *not* available unless you specifically include them.

Regards!

...JRF...

Manuales
Super Advisor

Re: If sentence ..

but problem is with if sentence, now i have this problem:

/home/scripts/test.sh[21]: Syntax error at line 21 : `if' is not matched

Thanks, Manuales.
Oviwan
Honored Contributor

Re: If sentence ..

Hi,

put su - user before the script in your crontab

Regards
Oviwan
Honored Contributor

Re: If sentence ..

Hi,

put su - USERNAME in front the script in your crontab

Regards