Desperate for help with menu coding

I am extremely desperate for help with this menu coding problem I'm having. Whenver I go to execute my script file, I keep getting an error message that says the following:

option: Undefined variable.

I implore someone to PUH-LEEZE point me in the right direction. I can't stress my appreciation. If I could beg, I would. Anyone, please help me. Thank you very much. My code follows:

#! /bin/csh

cat <<ENDINPUT

Menu of Options

  1. Display all files in a user's home directory
  2. Welcome yourself to the program
  3. Display System Information
  4. Exit back to Windows

ENDINPUT
echo Please enter your choice:
read option
case "$option" in
1)
ls -l
;;
2)
echo welcome
;;
3)
uname -a
;;
4)
exit
;;
*)
echo "Use 1, 2, 3, or 4"
;;
esac

Change the first line to

#!/bin/sh

also put a

while true; do
.....
.....
done

around the cat/read/case stuff so it repeats itself until 4 is selected.

That didn't change anything. I'm still getting the message that "option" is an undefined variable. I'm ready to pull my hair out.

Porter,

Okay, ignore my last post. I didn't see the second part of your response. What exactly do you mean by "put it around the /cat/read/case stuff"? I'm lost.

This works on Solaris 9:

#!/bin/sh

while true; do

cat <<ENDINPUT

Menu of Options

1. Display all files in a user's home directory
2. Welcome yourself to the program
3. Display System Information
4. Exit back to Windows

ENDINPUT
echo Please enter your choice:
read option
case "$option" in
        1)
                ls -l
                ;;
        2)
                echo welcome
                ;;
        3)
                uname -a
                ;;
        4)
                exit
                ;;
        *)
                echo "Use 1, 2, 3, or 4"
                ;;
esac

done

I'm not using Solaris 9. I'm just using plain, ol' Unix from what I know. I'm still getting the error message that option is an undefined variable.

I put in the while statement and it's now telling me the following:

while: Expression Syntax

Now it won't even bring up the menu.

(a) type "uname -a" and post results

(b) post your script within CODE brackets as I have done

(c) your UNIX does not support "/bin/sh" ?

AIX lc3bd1 3 4 00016D4F4C00

... and post your code in [ CODE ] brackets as I have done...

#!/bin/csh

cat <<ENDINPUT

Menu of Options

1. Display all files in a user's home directory
2. Welcome yourself to the program
3. Display System Information
4. Exit back to Windows

ENDINPUT
echo Please enter your choice:
read option
case "$option" in

1)
   ls -l
   ;;
2)
   echo welcome
   ;;
3)
   uname -a
   ;;
4)
   exit
   ;;
*)
   echo "Use 1, 2, 3, or 4"
   ;;
esac

So when I suggest you change the line

#!/bin/csh

to

#!/bin/sh

what did you think I meant?

Porter,

Well, I made the switch to /bin/sh as you recommended. Sorry, I didn't see that earlier or wasn't paying attention. I am now able to execute options 2 and 3. However, when I enter 1 or 4, it says the following:

ksh: 1: not found
or for option 4
ksh: 4: not found

Plus, I wasn't thinking but after entering one of these options except #4, I need to be able to bring the menu back up.

That's because you fell out of the menu script and are expecting the ksh shell to understand your menu options.

Did you notice my "while true; do ...... done"?

I know I am new to this forum and I dont want to rock the boat but.......

this is your third thread about this problem, sorry but it sounds like a homework problem.

if it is a homework problem then this may not be the best place to look for answers.

if you need this for work them you may be out of your depth in your job, if your job needs shell scripting skills then you may have a big learing curve.

you cant expect people on the forum to give you a finished script to solve your problems.

I hope I havent over stepped the mark....

I think the deadline is looming as well. :slight_smile:

Porter,

This is great! I am making significant progress. Here is the new code:

#!/bin/sh

while true; do
cat <<ENDINPUT

Menu of Options

1. Display all files in a user's home directory
2. Welcome yourself to the program
3. Display System Information
4. Exit back to Windows

ENDINPUT
echo Please enter your choice:
read option
case "$option" in

1)
   ls -l
   ;;
2)
   echo welcome
   ;;
3)
   uname -a
   ;;
4)
   exit
   ;;
*)
   echo "Use 1, 2, 3, or 4"
   ;;
esac
done

Now, when I select Option #4 it does not exit the program. I need to shut down the connection completely and return to Windows. Right now, it's just going to my home directory.

Gee, thanks for the input robs.

A while back in an earlier post I asked what does "Exit to Windows" mean?

What does an AIX box know or care about you and Windows?

It means that executing/choosing that option quits the connection to the Unix server, closes the command prompt window, and returns the user to the Windows desktop.