Reputation: 432
I have written a simple shell script for TCsh shell. The code is just to take an input from the user and then run something based on the input. I have used switch case for this but my PROBLEM is whatever I enter it ends up executing the default case.
#!bin/tcsh
echo "creating workdir = setup "
echo "extracting = extract"
echo "creating setups= create "
echo "validate = all(for running all validation),ve ,fa ,annotate ,Lib, CDL"
set user_input = "$<"
echo "entered string is -" $user_input
switch (user_input)
case setup:
./validateSource -sc -setup -check ve fa annotate Lib CDL -source source -library library -reference reference
breaksw
case extract:
./validateSource -sc -extract -check ve fa annotate Lib CDL -source source -library library -reference reference
breaksw
case (create):
./validateSource -sc -create -check ve fa annotate Lib CDL -source source -library library -reference reference -workdir workdir_nowb_EDA_7p2
breaksw
case (all):
./validateSource -sc -validate -check ve fa annotate Lib CDL -workdir workdir_nowb_EDA_7p2 -force
breaksw
case (ve):
./validateSource -sc -validate -check ve -workdir workdir_nowb_EDA_7p2 -force
breaksw
case (fa):
./validateSource -sc -fa -check ve -workdir workdir_nowb_EDA_7p2 -force
breaksw
case (annotate):
./validateSource -sc -validate -check annotate -workdir workdir_nowb_EDA_7p2 -force
breaksw
case (Lib):
./validateSource -sc -validate -check Lib -workdir workdir_nowb_EDA_7p2 -force
breaksw
case (CDL) :
./validateSource -sc -validate -check CDL -workdir workdir_nowb_EDA_7p2 -force
breaksw
default :
echo "wrong string entered"
endsw
Upvotes: 0
Views: 303
Reputation: 143906
If you have to use csh, (you should seriously consider @Basile Starynkevitch's advice), there's a couple of things wrong with your script.
First, you're missing a /
in the first line:
#!/bin/tcsh
And your switch
statement is wrong, you need a $
in front of your variable:
switch ($user_input)
You can probably take it from here. Note that if you type create
, it won't match (create)
, which is what you have in your case
statement.
Upvotes: 1
Reputation: 1
Read the famous csh considered harmful paper.
Consider using another shell. The most portable is to restrict yourself to posix shell (with dash
, bash
or even zsh
providing good compliance when correctly configured).
My preference go to zsh
.
To debug your shell script, try passing -v
and -x
to the shell, e.g. /bin/tcsh -x -v yourshellscript
Upvotes: 2