Dynamic Menu Help | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Dynamic Menu Help

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-30-2006
ScottKe ScottKe is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 1 September 2006, 4:40 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Question Dynamic Menu Help

I'm working on a menu to read folders in as menu selections then CD to the selected folder and display the contained files as menu selections for execution.

I'm using the following to read in the file list but I get lost after that.
I only read in files that begin with CAPs. The problem is when I quit from the file menu it doesn't re-display the top level folder menu and reset PS3.

Thanks!

#!/bin/ksh
#

PS3="Select System Type>"

select FILE in [A-Z]* QUIT
do
if [ -e $FILE ] ; then
cd $FILE

PS3="Select Test to Run>"
select TEST in [A-Z]* QUIT
do
if [ -e $TEST ] ; then
./$TEST
else
break
fi
done
else
break
fi
done
Sponsored Links
    #2  
Old 08-30-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
 
Join Date: Feb 2006
Last Activity: 2 February 2012, 9:30 AM EST
Location: Indianapolis, IN
Posts: 255
Thanks: 0
Thanked 2 Times in 2 Posts
I don't know exactly how your script is intended to work, but I wrote an example script to demonstrate traversing hierarchical menu choices. Maybe it will help (no guarantees that you can't break the script; it makes assumptions).
Code:
#!/usr/bin/ksh
# The quick brown fox jumps over the lazy dog

set -A animalname "fox" "dog"
set -A foxadject "quiet brown" "quick brown" "lazy brown" "quick red" "red slow"
set -A dogadject "slow" "quiet" "sleeping" "lazy" "brown"
set -A action "jump" "run" "skip" "hop" "roll"

until [[ -n $animal && -n $foxadj && -n $dogadj ]]
 do
  clear
  choice=1
  print "\nPlease select an animal.\n"
  select animal in ${animalname[*]}
   do
    choice=2
    print "\nPlease select a description for the $animal.\n"
    case $animal in
      fox)
        select foxadj in "${foxadject[@]}"
         do
          break $choice
        done
        ;;
      dog)
        select dogadj in "${dogadject[@]}"
         do
          break $choice
        done
        ;;
    esac
    break $choice
  done
done

until [[ -n $verb ]]
 do
  print "\nPlease select an action.\n"
  select verb in "${action[@]}"
   do
    break
  done
done

print "\nThe $foxadj fox ${verb}s over the $dogadj dog.\n"

Sponsored Links
    #3  
Old 08-30-2006
ScottKe ScottKe is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 1 September 2006, 4:40 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Nice program but the 'choices' are embedded in the script. I want to be able to add files to be executed to the menu simple by placing them in the folder instead of hard coded in the script. I didn't want to have to edit the script everytime a test is added.

What I've got reads the top level folders into the menu.

1)Folder1
2)Folder2
3)QUIT
Select System Type>

Once a choice is made here the next menu display the available filelist for execution in that folder.

1)Script1
2)Script2
3)Script3
...
7)Script7
8)QUIT
Select Test to Run>

The problem is when I 'QUIT' from menu 2 I still get menu2 prompt but it's actually at menu1. It doesn't display menu1 either. Simply:

Select Test to Run>
    #4  
Old 08-30-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 26 July 2014, 12:11 PM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 Posts
maybe something like this:

Code:
#!/bin/ksh

type_prompt='Select System Type> '
PS3="${type_prompt}"

file_choices=[A-Z]*
select FILE in ${file_choices} QUIT
do
   if [ -e $FILE ] ; then
     cd $FILE

     PS3="Select Test to Run>"
     select TEST in [A-Z]* QUIT
     do
        if [ -e $TEST ] ; then
          ./$TEST
        else
          cd ..
          PS3="${type_prompt}"
          break
        fi
     done
  else
     break
  fi
  # added to display  the OUTTER menu
  REPLY=''
done


Last edited by vgersh99; 08-30-2006 at 06:21 PM.. Reason: added display of the initial menue
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dynamic Drop Down Menu JayC89 Web Programming 2 08-19-2010 11:27 AM
Assigning values to reference variables for a dynamic menu driven script. kchinnam Shell Programming and Scripting 5 04-30-2010 02:41 PM
dynamic Select menu rawatds Shell Programming and Scripting 2 12-06-2004 04:54 AM
Dynamic select with multiple word menu items domivv Shell Programming and Scripting 5 07-22-2004 08:52 AM



All times are GMT -4. The time now is 01:12 PM.