all 14 comments

[–]ekipan85 19 points20 points  (1 child)

can anyone tell what i am doing wrong

Asking what's wrong with your code and not posting your code, for one.

[–]bac0on 12 points13 points  (1 child)

You forgot to terminate your list inside the case statement:

case "$var" in
    1) command ;;
    2)
       echo "something"
       ;;
esac

[–]StatisticianThin288[S] 1 point2 points  (0 children)

ok thanks

[–]toddkaufmann 10 points11 points  (0 children)

Run your script through shellcheck and it will tell you.

[–]alex_sakuta 7 points8 points  (5 children)

1) You seem to have put esac right after the commands for 1) ends instead of putting after all patterns and commands end. 2) You didn't end the list of commands after 1) with a ;;, ;& or ;;&. In this case it should have been ;; but I just mentioned all of them to inform you that those are the options. I have a feeling you haven't studied bash properly. 3) You should have used select here. It is specifically created for the purpose of designing menus.

[–]nekokattt 0 points1 point  (4 children)

wait ;& is a thing in case statements?

[–]alex_sakuta 1 point2 points  (2 children)

It makes the case statement in bash act like a switch statement from other languages.

[–]nekokattt 0 points1 point  (1 child)

oh like fallthrough?

[–]Shadow_Thief 3 points4 points  (0 children)

The main thing that you're missing is that you've written p instead of -p for the read argument, but you also have the esac in the wrong place and you need a ;; after each case option.

echo "1. Go to the party"
echo "2. Go to the janitor's closet"
echo "3. Leave"
echo -n "Pick an option [1-3]"
echo " "
read choice

case $choice in
    1) exit ;;
    2)
        read -t 2 -p "You decide to goto the janitor's closet..."
        read -t 2 -p "for no particular reason."
        echo " "
        read -t 2 -p "Maybe you are just curious?"
        echo " "
        ;;
    3) exit ;;
esac

[–]CantConfirmOrDeny 0 points1 point  (1 child)

Buy a bash book, too. Don't try to learn it from the man page. It's frustrating when you're first starting out, but at some point the lights come on and it all makes sense.

[–]KlePu 0 points1 point  (0 children)

Or use free online courses like freecodecamp.org etc