![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regarding interactive ID of batch job | pradeep.edara | UNIX for Dummies Questions & Answers | 1 | 12-20-2007 10:49 AM |
| Interactive menu | Klashxx | Shell Programming and Scripting | 0 | 12-11-2007 10:03 AM |
| create array holding characters from sring then echo array. | rorey_breaker | Shell Programming and Scripting | 5 | 09-28-2007 08:42 AM |
| Interactive Mode? | Nomad | UNIX for Dummies Questions & Answers | 2 | 08-16-2002 06:59 AM |
| Interactive String | odogbolu98 | Shell Programming and Scripting | 3 | 06-20-2002 01:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Interactive Array Menu
This should be simple, but i haven't done it before...
KSH I am reading a file into an array and currently displaying the values to the screen. What I need to do is to display a subset of those values, likely numbered, and prompt the user to select one. When they enter the number, it retrieves the assoicated array value and outputs it to the screen. (this will be used for more complex functions later) For example, the program is run and the first 10 rows are displayed. I select a number or hit a character to proceed to the next page. This would dump the first 10 rows and load the next 10 (into another array?) I select a value and the row associated with that value echoes to the screen. Any suggestions are greatly appreciated. My code so far: Code:
#!/bin/ksh
# define array
set -A line_array
# select input file
file_name="$scripts/cb_list.dat"
# populate the array
i=0
while read file_line
do
line_array[i]=${file_line}
let i=${i}+1
done < ${file_name}
i=0
while [ ${i} -le ${#line_array[*]} ]
do
echo ${line_array[i]}
let i=$i+1
done
# end of variable_define.sh
Last edited by gecko2424; 07-25-2008 at 09:48 AM.. |
|
||||
|
No need to 'dump' the values since you already have all of them loaded in the array, you can just calculate the current page offset, (say 10 for the second page), and just display items 11-20 in the array for that page.
Your code looks fine so far, what part are you having difficulty with? |
|
||||
|
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 01:41 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|