Sponsored Content
Top Forums Shell Programming and Scripting Generating a list of choices in a menu Post 94980 by vgersh99 on Thursday 5th of January 2006 10:06:38 AM
Old 01-05-2006
assuming your '/tmp/hosts.txt' contains:
Code:
host1
host2
host3
host4

here's one way of creating a 'menue':
Code:
#!/bin/ksh

hosts='/tmp/hosts.txt'
PS3="Pick one of the above: "

select i in $(< ${hosts})
do
      [ $i ] && print "you picked->[${i}]" || print -u2 'invalid selection'
done

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating menu list from configuration file

Hi folks, I have the following function ,which generates menu for installation type: select_install_type() { echo echo ======================================== echo Please select the type of installation: echo ======================================== ... (8 Replies)
Discussion started by: nir_s
8 Replies

2. Shell Programming and Scripting

reappearing menu list using select

is there a way I can make the menu list reappear when I use select ? ----- menulist="Change_title Remove_tag Change_tag Add_line Quit" select word in $menulist #change_title remove_tag change_tag add_line quit do case $word in # first menu option Change Title ... (9 Replies)
Discussion started by: forever_49ers
9 Replies

3. UNIX for Dummies Questions & Answers

Using a list menu as a variable

Hi again I have the follwing - cat ~/ABCFILE | grep "$SYSTEM" | grep "$USERNAME" What I'm looking to do is have the variable for $SYSTEM determined by the user making a selection from a numbered list. So, input 1 would be system ABC etc. I'm very puzzled as to how to go about this? Any... (3 Replies)
Discussion started by: Great Uncle Kip
3 Replies

4. Shell Programming and Scripting

Menu list in Unix csh - command not found

Hello, im taking a class of Unix and i dont really know much about it, im trying to create a list of menu a user would select from and im very lost. Basically it will have 5 options, the user will chose from: 1. list files in the pwd 2. display date and time 3. is the file file or directory 4.... (5 Replies)
Discussion started by: morava
5 Replies

5. Shell Programming and Scripting

generating the variable list for WHILE READ statement at runtime

Hi, I am reading the contents of a file in variables as - cat ${var_file_name} | while read COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 The problem is ... my file can have any number of columns - 5, 10, 11 .... So i want a dynamic variable list as - cat ${var_file_name} |... (8 Replies)
Discussion started by: gopalss
8 Replies

6. Red Hat

Menu system for terminal like Putty for host /ip list

Is there a way to create a menu in Gnome terminal to have a list of hosts with ip's like in Putty on Windows? (2 Replies)
Discussion started by: jlouki01
2 Replies

7. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

8. Programming

Listing Option Menu Choices from Text File

Hello, I am starting up a tool and one of the initial steps is to select a site/location which is being read from a text file. Here is the text file contents: site1 site2 site3 Here is the code: #!/usr/bin/python from Tkinter import * (3 Replies)
Discussion started by: tattoostreet
3 Replies

9. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies
Permute(3pm)						User Contributed Perl Documentation					      Permute(3pm)

NAME
String::Glob::Permute - Expand {foo,bar,baz}[2-4] style string globs SYNOPSIS
use String::Glob::Permute qw( string_glob_permute ); my $pattern = "host{foo,bar,baz}[2-4]"; for my $host (string_glob_permute( $pattern )) { print "$host "; } # hostfoo2 # hostbar2 # hostbaz2 # hostfoo3 # hostbar3 # hostbaz3 # hostfoo4 # hostbar4 # hostbaz4 DESCRIPTION
The "string_glob_permute()" function provided by this module expands glob-like notations in text strings and returns all possible permutations. For example, to run a script on hosts host1, host2, and host3, you might write @hosts = string_glob_permute( "host[1-3]" ); and get a list of hosts back: ("host1", "host2", "host3"). Ranges with gaps are also supported, just separate the blocks by commas: @hosts = string_glob_permute( "host[1-3,5,9]" ); will return ("host1", "host2", "host3", "host5", "host9"). And, finally, using curly brackets and comma-separated lists of strings, as in @hosts = string_glob_permute( "host{dev,stag,prod}" ); you'll get permutations with each of the alternatives back: ("hostdev", "hoststag", "hostprod") back. All of the above can be combined, so my @hosts = string_glob_permute( "host{dev,stag}[3-4]" ); will result in the permutation ("hostdev3", "hoststag3", "hostdev4", "hoststag4"). The patterns allow numerical ranges only [1-3], no string ranges like [a-z]. Pattern must not contain blanks. The function returns a list of string permutations on success and "undef" in case of an error. A warning is also issued if the pattern cannot be recognized. Zero padding An expression like @hosts = string_glob_permute( "host[8-9,10]" ); # ("host8", "host9", "host10") will expand to ("host8", "host9", "host10"), featuring no zero-padding to create equal-length entries. If you want ("host08", "host09", "host10"), instead, pad all integers in the range expression accordingly: @hosts = string_glob_permute( "host[08-09,10]" ); # ("host08", "host09", "host10") Note on Perl's internal Glob Permutations Note that there's a little-known feature within Perl itself that does something similar, for example print "$_ " for < foo{bar,baz} >; will print foobar foobaz if there is no file in the current directory that matches that pattern. String::Glob::Permute, on the other hand, expands irrespective of matching files, by simply always returning all possible permutations. It's also worth noting that Perl's internal Glob Permutation does not support String::Glob::Permute's [m,n] or [m-n] syntax. COPYRIGHT &; LICENSE Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to the contents of this file are licensed under the Perl Artistic License (ver. 15 Aug 1997). AUTHOR
Algorithm, Code: Rick Reed, Ryan Hamilton, Greg Olszewski. Module: 2008, Mike Schilli <cpan@perlmeister.com> perl v5.12.4 2009-01-29 Permute(3pm)
All times are GMT -4. The time now is 03:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy