LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-03-2013, 10:01 PM   #1
neocontrol
Member
 
Registered: Jul 2005
Posts: 273

Rep: Reputation: 31
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

Last edited by neocontrol; 01-03-2013 at 10:07 PM.
 
Old 01-03-2013, 10:42 PM   #2
neocontrol
Member
 
Registered: Jul 2005
Posts: 273

Original Poster
Rep: Reputation: 31
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...
 
  


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash: Checking for lower case and upper case letters in a string fatalerror0x00 Programming 1 12-09-2012 03:17 AM
bash: if block inside select' agrestic Linux - Software 1 01-14-2009 05:01 PM
Does CGI/PERL have a Select Case Statement? craig467 Programming 2 02-16-2007 05:33 PM
Bash select statement and spaces meshcurrent Linux - General 2 04-09-2003 10:35 AM
bash: can't get out of SELECT adam_boz Programming 2 09-17-2002 12:53 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration