NonCreature0714 NonCreature0714 - 1 year ago 72
Bash Question

tsch: case statement isn't evaluating

EDIT: I originally thought my variable wasn't accepting input from the keyboard. I've corrected my question to more accurately reflect the issue.

In the script below, the case statement isn't evaluating.

I'm pretty new to tcsh... I just want

to accept characters
as input from the keyboard, which I'm not sure it is, and run the switch statement correctly.

I'm reading Sobell's "A Practical Guide to Linux Commands, Editors, and Shell Programming." My syntax seems correct based on the book's chapter 9 on tcsh, but, at this point, I have not idea what I'm doing wrong.

Searching through SO didn't yield similar questions, so either this is painful obvious to many, or no one's asked yet.

Can some one more experience take a look and indicate my error?

# menu interface to simple commands
set input_line = ''
echo "\n COMMAND MENU\n"
echo " a. Current date and time"
echo " b. Users currently logged in"
echo " c. Name of the working directory"
echo " d. Contents of the working directory\n"
echo -n "Enter a, b, c, or d: "
set input_line = "$<"
switch ($input_line)
case of [aA*]:
case of [bB*]:
case of [cC*]:
case of [dD*]:
echo "There is no selection: $input_line"

Just to be clear, I can get a script which does the exact same thing in bash to work correctly, but I'm focused on tcsh.

Answer Source

This line:

set input_line = "$<"

is working just fine. The problem is that you have the syntax of the case labels wrong. Change case of to case and it should work.

(I'm curious why you thought the of was necessary.()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download