How to use a multiple line list with the select command in ksh?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use a multiple line list with the select command in ksh?
# 1  
Old 08-23-2013
How to use a multiple line list with the select command in ksh?

I copied the below program to play around with displaying a list of items using the select command in ksh. When I put all items in the same line, it works fine. I am trying to use multiple lines instead of a single row...my list is too large for a single line. How do I get the line continuation to work properly. The initial script used a "\" at the end of the 2nd, 3rd, and 4th lines in the "select" command...this only displayed the "\" before the ^J. I took the "\" out, but that didn't change the output format. Here's the code:
Code:
#!/bin/ksh

set -A termnames gl35a t2000 s531 vt99
echo "\n"
print 'Select your terminal type:'
echo "\n"
PS3='terminal? '
select term in '
    'Givalt GL35a'
    'Tsoris T-2000'
    'Shande 531'
    'Vey VT99''
do
    if [[ -n $term ]]; then
        TERM=${termnames[REPLY-1]}
        print "TERM is $TERM"
        break
    fi
done

***********************************
The output below is from the above "select" command:

Select your terminal type:


1) ^J    Givalt
2) GL35a^J    Tsoris
3) T-2000^J    Shande
4) 531^J    Vey
5) VT99
terminal? 1
TERM is gl35a

I have also tried removing the single quotes that surround the list in the select command, but this returns the syntax error:

termname.sh[8]: syntax error at line 9 : `newline or ;' unexpected


Any help would be greatly appreciated.

Thanks,
Jeff

Last edited by vbe; 08-23-2013 at 12:56 PM.. Reason: code tags please for your code and data
# 2  
Old 08-23-2013
Instead of using single quotes around all of the terms, simply continue the list by ending each line of the list, except the last, with a backslash (you can use this to continue any shell command).

Regards,
Alister
# 3  
Old 08-23-2013
alister...thank you so much. The original code did not have a "\" after "select term in"...which is the first line in the command. I could've sworn that I tried that, but after countless changes, I needed a new set of eyes. Works like a charm.

One more question. If you don't have a quick fix, you can tell me to do another post, but, I wanted to know if there is a way to display a multi-column list? Would I use select again or something else?

Thanks in advance,
Jeff
# 4  
Old 08-23-2013
What do you mean by "multi-column-list"? Pls post example. If there's enough list items, select will split them into several columns istself:
Code:
select term in "Givalt GL35" "Tsoris T-2000" "Shande 531" "Vey VT99" "Givalt GL35" "Tsoris T-2000" "Shande 531" "Vey VT99"; do echo $term; done
1) Givalt GL35      3) Shande 531        5) Givalt GL35    7) Shande 531
2) Tsoris T-2000  4) Vey VT99        6) Tsoris T-2000  8) Vey VT99

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

2. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Unix command to select first few characters and last character of a line

I have a huge file and I want to select first 10 charcters and last 2 characters of everyline and than will filter the unique line. I know, it must be easy bt I am new to unix scripting:) Ex. I have file as below and need to e3kbaird and last 2 characters. and than unique records. ... (3 Replies)
Discussion started by: Sanjeev Yadav
3 Replies

5. UNIX for Advanced & Expert Users

Running ksh script from command line

Hi. I have a ksh script I want to run, but I'm connecting through a telnet and I don't want to FTP the scripts itself. is there a way of running the script from command line ? like ksh "The script itself..." Thanks, Ramon (4 Replies)
Discussion started by: mellowcandle
4 Replies

6. Shell Programming and Scripting

problem with KSH script: command line args

Hi I am executing a KSH script by passing command line arguments example: Red Green Dark Red Blue when I am splitting the arguments by using " "(Space) as delimiter But the colour Dark Red is a single parameter. But it is getting splitted in between How to avoid this. Please help Also... (4 Replies)
Discussion started by: hemanth424
4 Replies

7. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

8. Shell Programming and Scripting

KSH: Reading a file line by line into multiple arrays

Hi - I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd... (2 Replies)
Discussion started by: sniper57
2 Replies

9. UNIX for Dummies Questions & Answers

Ksh Storing Multiple Files and reading each line in each file.

How would I go about storing multiple file paths in a directory that begin like: 20080402* and run a loop that reads each line of each file thats in a given directory. So far this is what I have: #!/bin/ksh echo "ENTER Reprint Date (YYYYMMDD): " read ReprintDate echo ""... (1 Reply)
Discussion started by: developncode
1 Replies
Login or Register to Ask a Question