Sponsored Content
Full Discussion: Interactive Array Menu
Top Forums Shell Programming and Scripting Interactive Array Menu Post 302220358 by gecko2424 on Thursday 31st of July 2008 12:19:48 PM
Old 07-31-2008
EDIT:
I have it working now, code is below for anyone that it might help. I did what i needed with a nested function.

Code:
#!/bin/ksh
# define array
set -A line_array

# select input file
file_name="cb_list.dat"


# populate the array
i=1

while read file_line
do
   line_array[i]=${file_line}
   let i=${i}+1
done < ${file_name}


#Display selection options
i=1
x=10

var_select ()
{
while [ ${i} -le ${x} ] && [ ${i} -lt ${#line_array[*]} ]
do
 echo
 echo $i ${line_array[i]}
  let i=$i+1
done

#Select an option

    echo
    echo "Select an option number or press enter: \c"
    read num
disp_select
}


disp_select ()
{
if [ ${num} -le ${i} ]
  then
    echo "You have selected: ${line_array[num]}"
else
    x=${x}+10
    var_select
fi
}

var_select


# end


Last edited by gecko2424; 07-31-2008 at 02:41 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Interactive menu

Hi ,some time ago i did an interactive menu based on eval function for navigation , one of the post remind me it. I think it could be handy for others. #!/usr/bin/ksh keyRead () { tput smso echo "Enter option." tput rmso oldstty=$(stty -g) stty -icanon -echo min 1 time 1 Answer=$(dd... (0 Replies)
Discussion started by: Klashxx
0 Replies

2. Shell Programming and Scripting

Menu help with array selection

Hi there all I got the following I got multiple arrays named for example STAT_AAAA STAT_AAAB STAT_AAAC STAT_AAAD Now what I want I have chosen an option in a menu to select 1 but I dont want to write for all the same thing so I made it a signle one now what I want is to get STAT_ and... (6 Replies)
Discussion started by: draco
6 Replies

3. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

4. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

5. Shell Programming and Scripting

Execute interactive bash menu script in browser with PHP

I have an interactive menu script written in bash and I would like use PHP to open the interactive bash menu in a browser. Is this possible? Using the sytem() function in php runs the script but it's all garbled. Seems like maybe a terminal window needs to be opened in php first? ... (1 Reply)
Discussion started by: nck
1 Replies

6. Red Hat

Interactive PXE Boot Menu

I have been asked to modify our PXE server such that there will be only one entry in the pxelinux.cfg/default file, where the same kernel and initrd.img will be used regardless of what operating system is to be installed, and the user will type in the path to the kickstart file that will be used. ... (7 Replies)
Discussion started by: ceb
7 Replies

7. Shell Programming and Scripting

Dialog menu with array

Hi I'm currently making a schoolproject and I'm stuck with reading an array into the possible options of a menu dialog. What I mean is: I've put some values into an array, I want all these values from the array to be possible to be selected in the menu. Please help :) I'm programming in Debian... (1 Reply)
Discussion started by: dan007255
1 Replies

8. Homework & Coursework Questions

Dialog menu with array

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi I'm currently making a schoolproject and I'm stuck with reading an array into the possible options of a... (1 Reply)
Discussion started by: dan007255
1 Replies

9. Shell Programming and Scripting

Passing positioning array as whiptail -- menu option

I may have asked this before, so forgive OF. Problem: I can pass positioning array as -- menu option to whiptail, but it does not show in the whiptail form as an array - only single (first member "lsusb" ) entry / line shows up. Code: DynamicEntry=$(whiptail \ --title "DEBUG... (1 Reply)
Discussion started by: annacreek
1 Replies

10. 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
ARRAY_RAND(3)								 1							     ARRAY_RAND(3)

array_rand - Pick one or more random entries out of an array

SYNOPSIS
mixed array_rand (array $array, [int $num = 1]) DESCRIPTION
Picks one or more random entries out of an array, and returns the key (or keys) of the random entries. PARAMETERS
o $array - The input array. o $num - Specifies how many entries should be picked. RETURN VALUES
When picking only one entry, array_rand(3) returns the key for a random entry. Otherwise, an array of keys for the random entries is returned. This is done so that random keys can be picked from the array as well as random values. Trying to pick more elements than there are in the array will result in an E_WARNING level error, and NULL will be returned. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | The resulting array of keys is no longer shuf- | | | fled. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_rand(3) example <?php $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . " "; echo $input[$rand_keys[1]] . " "; ?> SEE ALSO
shuffle(3). PHP Documentation Group ARRAY_RAND(3)
All times are GMT -4. The time now is 04:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy