LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09: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 09:07 PM.
 
Old 01-03-2013, 09: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



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 02:17 AM
bash: if block inside select' agrestic Linux - Software 1 01-14-2009 04:01 PM
Does CGI/PERL have a Select Case Statement? craig467 Programming 2 02-16-2007 04:33 PM
Bash select statement and spaces meshcurrent Linux - General 2 04-09-2003 09:35 AM
bash: can't get out of SELECT adam_boz Programming 2 09-16-2002 11:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:43 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration