#! /bin/bash # Name: menu1 # Purpose: Displays a menu in terminal and sends it output to STDOUT # Syntax: menu1 MenuTitle choice1 choice2 choice3 ..... # Output: The text of one of the chosen # Author: Michel Bisson # History: 12.09.2003 First inplementation of script #---------------------------------------------------------- # Allow minimum 3 parameters (title and 2 choices) if [ "$#" -lt 3 ] ; then echo "ERROR: Wrong number of parameters" echo "Syntax: $0 MenuTitle choice1 choice2 choice3 ....." exit 1 fi # Ask for a password echo -n "Please enter password: " read passwd #passw=$(dialog --stdout --passwordbox "Please enter password for using this script" 0 0) #echo $passwd #exit 0 if [ "$passwd" != $(cat ~/scrpasswd) ] ; then echo "ERROR: Wrong password." exit 1 fi # Save the menu title before deleting it(shift) from the parameter list title=$1 shift # Build-up the beginning of the dialog command command="dialog --stdout --menu $title 0 0 $#" # Build-up the rest of the dialog command parameters # Here we generate a tag (item number) in front of each # choice item in command parameter list counter=1 for param in $* ; do command=$command" "$counter" "$param let "counter++" done # Execute the dialog menu command # The result (item Nr.) is stored in variable '$result' result=$($command) # Ask if user want to display the result (result is exit code 0 for YES and 1 for NO) dialog --yesno "Do you want to dispaly the result of your choice?" 0 0 # Display the result of the choice if yes selected if [ "$?" -eq 0 ] ; then # Ask for a title for the display of the choice mytext=$(dialog --stdout --inputbox "Enter the display title of the result:" 10 60) # If the the OK button was presssed then # print the choice in a pop-up message # otherwise notify of cancellation in pop-up message if [ "$result" != "" ] ; then eval "choice=""\$""$result" dialog --msgbox "$mytext$choice" 0 0 else dialog --msgbox "Choice was cancelled" 0 0 fi fi