Sponsored Content
Full Discussion: array to choices .. lost
Top Forums Shell Programming and Scripting array to choices .. lost Post 302381847 by kenray on Monday 21st of December 2009 05:55:01 AM
Old 12-21-2009
array to choices .. lost

Hi Im' trying to output a list of files then make the list files as choices, need someone to give me hand.

so far here is what i got.. a bit messy

Code:
#!/bin/sh

menu_str=`ls -1 file*`

cnt=0
for i in $menu_str
do
menu_item[cnt]=${i}
cnt=$(($cnt+1))
echo $cnt 
echo ${menu_item[*]}
done

#echo $cnt ${menu_item[*]}
i=-1
echo Enter your number of choices
read choice
while [ $i -lt $cnt ]; do
        #echo "$i ${menu_item[$i]}"
        let i++
        if [ $i -eq $choice ]; then
                echo "you have chosen $i ${menu_item[$i]}"
                exit 1
        fi
done


#############################

should output something like:

Code:
echo "number  of choices <1 - $cnt>"
read $choices

Choice 1. File1111
Choice 2. File2223
Chioce 3. File1233

and so on..

If $choice is equal to array of choices then
echo you have chosen Choice 1.
echo do something...


Thanks

Last edited by pludi; 12-21-2009 at 07:29 AM.. Reason: code tags, please...
 

4 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Lost Data Lost Admin

First time so excuse my ignorance please. I may not be accurately describing the issue. I have inherited a small lab mostly SUN V120s. We lost power and are trying to recover. Nope no backups... The primary issue I have is 1 box is an Oracle Server. It has 2 36Gb harddrives. I am able to... (3 Replies)
Discussion started by: murphsr
3 Replies

2. Shell Programming and Scripting

Generating a list of choices in a menu

Hello all, I have the below script and I'm a little stuck on the best way to continue. Essentially I'm creating a text file (systems.txt) with a list of servers in it by hostname. Then I would like to echo a menu with each hostname and a number to use to pick it from the list. It's somehow... (7 Replies)
Discussion started by: sysera
7 Replies

3. Shell Programming and Scripting

Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter. IFS=$'\n' fortune_lines=($(fortune | fold -w 30 )) Inside of this line screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines}\r"`" And I am lost at this point. I am thinking something like this? Then make it loop.. ... (7 Replies)
Discussion started by: briandanielz
7 Replies

4. Solaris

Lost out-of-band communication with 2540 Array

Hello Dears, My server hots cannot contacted my array disk 2540 by using out-of-band Ethernet Cable. The Controller Ethernet port is off , I replace the ethernet cable but not OK I reboot the server and the Array disk 2540 but Not OK. Please somebody know how to solve this issue? ... (1 Reply)
Discussion started by: ghislino
1 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 11:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy