Bash script to give multiple choices and a varying number of answers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script to give multiple choices and a varying number of answers
# 1  
Old 10-01-2014
Bash script to give multiple choices and a varying number of answers

Hello everybody,

I use `case' quite a lot but , excellent as it is , it only gives one
final result ; can anyone suggest a way whereas , say long
lists of choices are given and I , or a user could select either one
two or any number of results to be echoed .

many thanks in anticipation

v686.
# 2  
Old 10-01-2014
Im not sure I understand... could you give a sample of your case usage( in code tags...), and what more you would like?
I dont get the "one two or any number of results to be echoed . "
# 3  
Old 10-01-2014
Eventually sth along this line:
Code:
ARR=( ABC DEF GHI JKL MNO PQR STU )
select CH in ${ARR[@]}
  do for ((i=0; i<${#REPLY}; i++))   
       do SE=${REPLY:$i:1}           
#          echo "CH= " $CH ", SE= " $SE ", REPLY= " $REPLY 
          case $SE in
                1) echo "Selected "$SE ", " ${ARR[0]} " = " ${ARR[$SE-1]};;
                2) echo "Selected "$SE ", " ${ARR[1]} " = " ${ARR[$SE-1]};; 
                3) echo "Selected "$SE ", " ${ARR[2]} " = " ${ARR[$SE-1]};; 
                4) echo "Selected "$SE ", " ${ARR[3]} " = " ${ARR[$SE-1]};; 
                5) echo "Selected "$SE ", " ${ARR[4]} " = " ${ARR[$SE-1]};; 
                6) echo "Selected "$SE ", " ${ARR[5]} " = " ${ARR[$SE-1]};; 
                7) echo "Selected "$SE ", " ${ARR[6]} " = " ${ARR[$SE-1]};; 
          esac
       done
  done
1) ABC
2) DEF
3) GHI
4) JKL
5) MNO
6) PQR
7) STU
#? 127       #          <----------- THREE selections in one go!
Selected 1 ,  ABC  =  ABC
Selected 2 ,  DEF  =  DEF
Selected 7 ,  STU  =  STU

# 4  
Old 10-01-2014
hello vbe ,

I haven't used case for this problem,for I know I'll only get one answer.
I should have been more specific rather than say : "one two or any number of results to be echoed ".
Directories: what I am trying, is to create a script that does this:
a) Echo a list of all directories;
b) Give a number or letter to each one;
c)I can then choose which directory or directories I wish to
be displayed using `ls' or its octal variation.

---------- Post updated at 07:48 PM ---------- Previous update was at 07:37 PM ----------

RudiC ,

I'm working on your code, I'll get back ,probably tomorrow.
Maybe I'll have indigestion ,{words !}.

v686.

Last edited by V686; 10-01-2014 at 03:40 PM.. Reason: in wrong place
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Select answers from multiple questions using shell script

I have a text file in this format Some lines.... Question no: 1 The question? A. Answer 1 B. Answer 2 C. Answer 3 D. Answer 4 Answer:B Some lines.... Question no: 2 The question? (choose 2) (10 Replies)
Discussion started by: zorrox
10 Replies

2. Shell Programming and Scripting

Script to Serach pattern and give number of occurrences

Hi, I want a script which search for a pattern "good" in a huge file and provide me number of occurences of such pattern in a file. lets say i have a file test.txt contents as below good is good but good is sometime bad and sometime good you are very good and good is always good ... (7 Replies)
Discussion started by: sv0081493
7 Replies

3. Shell Programming and Scripting

Perl script give answers by file

Hi, I am new in perl. I am running a perl installation script, its asking for paths and so many inputs. Can we provide that info by any file. so i can avoid the interactive installation. (2 Replies)
Discussion started by: Priy
2 Replies

4. Shell Programming and Scripting

Script variable help, Varying number of arguments to excute script

Hi Guy's. Hopefully someone can help me with what I am trying to archieve. So situation currently is, I have a script already setup however I have another script that sits infront of it. The main script basically goes and searchs multiple platforms for a list of entered data. In... (10 Replies)
Discussion started by: mutley2202
10 Replies

5. UNIX for Dummies Questions & Answers

How to give multiple inputs to a shell script

Got struck while trying to write a shell script which should automatically give input. While running a script for eg: (adpatch.sh) It Prompts for Multiple inputs like: Do you currently have files used for installing or upgrading the database installed in this APPL_TOP ? need to give... (2 Replies)
Discussion started by: abdmoha
2 Replies

6. Shell Programming and Scripting

Needed value after the last delimeter in a file with varying number of delimited columns

Hi All, My file has the records as below: aaa\bbb\c\dd\ee\ff\gg zz\vv\ww pp\oo\ii\uu How can I get the value after the last delimeter. My o/p: gg ww uu Thanks in Advance, (5 Replies)
Discussion started by: HemaV
5 Replies

7. Shell Programming and Scripting

Looking for help with script to assign all disk space to slice#0 on multiple disks of varying sizes

Hi Folks, I am trying to make a script to assign all diskspace to slice 0, on multiple sized disks. Since the disks are new they may need to be labelled also to avoid the error: Cannot get disk geometry Below is my code struggling with logic which doesn't seem to be producing the desired... (0 Replies)
Discussion started by: momin
0 Replies

8. Solaris

Please give answers for this interview questions

I was not able to get answers for these interview questions. It will be appreciable and useful if any one answers this questions. (5 Replies)
Discussion started by: Sesha
5 Replies

9. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies

10. Shell Programming and Scripting

Parse apart strings of comma separated data with varying number of fields

I have a situation where I am reading a text file line-by-line. Those lines of data contain comma separated fields of data. However, each line can vary in the number of fields it can contain. What I need to do is parse apart each line and write each field of data found (left to right) into a file.... (7 Replies)
Discussion started by: 2reperry
7 Replies
Login or Register to Ask a Question