LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Help with bash select and case (http://www.linuxquestions.org/questions/programming-9/help-with-bash-select-and-case-4175444061/)

neocontrol 01-03-2013 09:01 PM

Help with bash select and case
 
Hi,

I'm playing around with some bash. I am making a quick interface to eventually make a ssh connect menu.

My problem I'm having with the code below is that its not honoring my 'quit' and 'help'. When I enter a number for the host in question, it echos it out as expected.

I think I'm doing something wrong with strings and the case statements, but I'm not 100% sure.

Thanks in advance.

Code:

#!/bin/bash

PS3="Select: "
SERVERS=("host1" "host2" "host3")

select HOST in "${SERVERS[@]}";
do
  case $HOST in
    "quit")
      echo "Qutting..."
      break
    ;;
    "help")
      echo "Type in a number, we print it."
    ;;
    *)
      echo $HOST
    ;;
    esac
done


neocontrol 01-03-2013 09:42 PM

Figured it out. This seems to do the trick.

Code:

PS3="Select: "
SERVERS=("quit" "help" "host1" "host2" "host3")

# Select loop
select HOST in "${SERVERS[@]}"
do
    case $HOST in
      quit  ) echo "quiting"; break;;
      help  ) echo "Type in a number to connect to a server.";;
      *      ) echo $HOST;;
    esac
done

exit 0

Starting to make more sense...


All times are GMT -5. The time now is 07:36 PM.