LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2016, 06:56 PM   #1
tiffney2018
LQ Newbie
 
Registered: May 2016
Posts: 4

Rep: Reputation: Disabled
cannot figure out how to alter a message displayed when an option is chosen


I am trying to modify an option in the shell script I am working on and can't figure out why the menu option is not functioning properly.

when I choose 1 in the menu command, my goal is for the outcome to display "File Directory Listing" from its original
"you chose option one".

However when I alter the message the output given is
invalid option!

I have included my script below.

Sorry for not using code block I am very new and learning so much it is extremely overwhelming.


Any help is appreciated.

Thank you
Tiffney
--------------------------------------------------------------

#!/bin/bash
PS3='Please enter your choice:'

options=("option 1 -File Directory?" "option 2-?" "option-3?" "Quit")

select opt in "${options[@]}"

do

case $opt in

"option 1-?")
echo "File Directory Listing"

;;

"option 2-?")
echo "you chose option 2"

;;


"option 3-?")
echo "you chose option 3"

;;

"Quit")
break
;;

*) echo invalid option;;

esac

done

Last edited by tiffney2018; 05-07-2016 at 07:13 PM. Reason: info left out
 
Old 05-07-2016, 07:03 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Well... You left out a quote in option 2 and option 3... I think that confused the parser into making everything invalid.

Second, You didn't fully specify the option. In you select, you used "option 1 -File Directory?", but you did not use that specific string as the option - so it didn't match.

Third, your "option-3?" is not "option 3-?" so it doesn't match either.

And you still aren't using code blocks.

If you want better error checking, use the -vx options on bash.

You could also echo what your selection was to see what should be matched.

I also suggest you look a little closer at the documentation for the case structure. I think you are going to want to use some wildcards...

Last edited by jpollard; 05-07-2016 at 07:25 PM.
 
Old 05-07-2016, 07:35 PM   #3
tiffney2018
LQ Newbie
 
Registered: May 2016
Posts: 4

Original Poster
Rep: Reputation: Disabled
I corrected the quotes I left out. It was because I couldn't get the script to paste and had to re-type it.

I don't think I am using code block properly!
 
Old 05-07-2016, 07:39 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You may want to re-read the section on select too. Check the reference to the "REPLY" environment variable. It can shorten you strings for the case structure.

Code blocks are the sequence [ code ] and [ /code ] (without the spaces).

The results look like:
Code:
#!/bin/bash
PS3='Please enter your choice:'

options=("option 1 -File Directory?" "option 2-?" "option 3?" "Quit")
... and so forth ... :)
If you go to the "Go Advanced" editing, there are two rows of options above the text window. If you put your mouse over the option it will tell you how to use it (the "#" option is the one that you want).

Last edited by jpollard; 05-07-2016 at 07:44 PM.
 
  


Reply



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] Change displayed message in pam_cracklib? theillien Linux - Security 4 07-22-2011 11:24 AM
I can't figure out the error message. Gins Programming 42 01-02-2008 12:30 AM
Kdar hogs cpu after writting all backup. Cancel only displayed option! suguru SUSE / openSUSE 4 12-19-2005 06:37 AM
How to alter table with no check option minil Programming 0 08-05-2005 08:11 AM
shell error messages not displayed as a message box!!! user222 Linux - General 10 10-25-2004 01:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 PM.

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