1753666 Members
6420 Online
108799 Solutions
New Discussion юеВ

C-shell script

 
SOLVED
Go to solution
Ionut Grigorescu_2
Super Advisor

C-shell script

Hi gurus,

I want to write an interactive line in a C-shell script which asks the operator if he/she wants to continue - something like :
"Do you want to continue ? [y]es/[n]o: "
set answer=($<)
when I try to test answer
if ($answer =~ [yY])
it returns me no match - I have tried also with [Y][y] and also with == operator,

where am I wrong? I must wite it in csh - this is the used shell for this user.

Thank you,
ionut
If it weren't for STRESS I'd have no energy at all
5 REPLIES 5
malay boy
Trusted Contributor

Re: C-shell script

try this :

echo "Do you want to continue ? [y]es/[n]o: \c"

read ans

echo $ans

ans=input from user

regards
mB
There are three person in my team-Me ,myself and I.
Massimo Bianchi
Honored Contributor

Re: C-shell script

Hi,
just for test,
what is the content of $answer?

Try visualizing it with a

set -x

at the beginning of the script. Honestly i do not know what the sintax " $< " means...

Maybe using a

read answer

will do the trick.

Massimo
Ionut Grigorescu_2
Super Advisor

Re: C-shell script

Hi,

this syntax set a=($<) is proposed in "Shells: User's guide" book from HP for interactive shell-scripts for c-shell.
just for test: when I type y as answer it returns me:
y =~[Yy] no match
If it weren't for STRESS I'd have no energy at all
Massimo Bianchi
Honored Contributor
Solution

Re: C-shell script

this works:

#if ( "y" =~ [yY] ) then; echo GOT IT; endif
GOT IT
# setenv ANS y
# if ( $ANS =~ [yY] ) then; echo GOT IT; endif
GOT IT

try with more spaces ?
Massimo

Ionut Grigorescu_2
Super Advisor

Re: C-shell script

grazie, Massimo! The spaces were the problem...
case closed
If it weren't for STRESS I'd have no energy at all