Dialog and bash script, and fortunes,menu example

Here you can discuss every aspect of Debian. Note: not for support requests!

Dialog and bash script, and fortunes,menu example

Postby GarryRicketson » 2016-07-07 04:03

I was not to sure where to start, at first thought:
Programming
Need help with C, C++, perl, python, etc?



However, I am not looking for "help" really, After doing some searches, and also
using the manuals that comes with "fortune", "bash", and "dialog" the examples that come with the "Dialog" program, I came up with this :

Code: Select all
#!/bin/bash

#A menu example based on the menu example in dialog
#Also to give credit where it is due , http://linuxcommand.org/lc3_adv_dialog.php
#is where I found the menu example, improved and the basic bash script
#I only needed to modify a little.

DIALOG_CANCEL=1
DIALOG_ESC=255
HEIGHT=0
WIDTH=0

display_result() {
  dialog --title "$1" \
    --no-collapse \
    --msgbox "$result" 0 0
}

while true; do
  exec 4>&1
  selection=$(dialog \
    --backtitle "Bible Verses and Fortunes" \
    --title "Menu" \
    --clear \
    --cancel-label "Exit" \
    --menu "Please select:" $HEIGHT $WIDTH 4 \
    "1" "Fortune Bible Verses" \
    "2" "Display Daily Verse" \
    "3" "Display Fortune " \
    "4" "Spanish Fortune"\
    2>&1 1>&4)
  exit_status=$?
  exec 3>&-
  case $exit_status in
    $DIALOG_CANCEL)
      clear
      echo "Program terminated."
      exit
      ;;
    $DIALOG_ESC)
      clear
      echo "Program aborted." >&2
      exit 1
      ;;
  esac
  case $selection in
    0 )
      clear
      echo "Program terminated."
      ;;
    1 )
      result=$(fortune kjv)
      display_result "KJV Verses"
      ;;
    2 )
      result=$(verse)
      display_result "Daily Verse"
      ;;
    3 )
        result=$(fortune)
        display_result "Fortune"
      ;;
 4 )
      result=$(fortune kjv-es-1)
      display_result "Spanish KJV"
;;
  esac
done   

So any way, just thought I would share it.
Here is what it looks like :
Image

Using this to help with translating,.. :
apertium(1) apertium(1)

NAME
apertium - This application is part of ( apertium )

This tool is part of the apertium machine translation architec‐
ture: http://apertium.sf.net.
User avatar
GarryRicketson
 
Posts: 5877
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests

fashionable