Simple nested Case statment in while loop

So I know this question is pretty basic but I'm pretty new to programing of any kind and I've been working on it so long it's giving me a headache as I know the solution should not be that hard to come up with.

Here is the problem...

Using your knowledge of the while loop, take the program and nest the case statement inside a while loop, so the case statement will keep on running until q is typed. The spaces below are where the parts of the while loop, and the interactivity between the user and the program would go (ex. asking the user to enter a new choice, and allowing for it).

I'm guessing the first two missing lines (lines 9 and 10) are something like..

While ["$option" != quit]
do

and I know one of the last lines (17,18,19)is

done

with maybe the other two being something like echo "Type quit to exit the program or choose another option" and maybe a second read option line.

_______________________________________________________________________________
line 1: #!/bin/sh
line 2: clear
line 3: “Use one of the following options:”
line 4: echo “d To display the time and date”
line 5: echo “p To see what directory you are currently in”
line 6: echo “w To see a list of who is online”
line 7: echo “ Enter your option and hit Enter: \c”
line 8: read option
line 9:
line 10:
line 11: case $option in
line 12: d) echo `date`;;
line 13: p) echo `pwd`;;
line 14: w) echo `who`;;
line 15: *) echo “That was not a valid selection”;;
line 16: esac
line 17:
line 18:
line 19:
line 20: echo “Good Bye”
______________________________________________________________________________

Any help would be appreciated.
Even though this is the Unix section, this is still a C++ forum. You're better off finding another forum to get help with shell scripts.
this is the basic idea. you need to round off the edges.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

while true
do
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo `date`
            ;;
        "Option 2")
           echo `pwd`
            ;;
        "Option 3")
            echo `who`
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done
done
Last edited on
Topic archived. No new replies allowed.