To-Slalom

Menu

Apr 26th, 2021
793
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # criacao de um menu
  4. pause_script () {
  5.     echo -n "Press any key to continue "
  6. }
  7. # dummy array
  8. array=("aa" "bb" "cc")
  9. title_array=( "Amostrar ano atual  #" "Amostar mes actual  #" )
  10. func_array=("$(date +%B)" "$(date +%Y)")
  11.  
  12. # count array
  13. count=${#title_array[@]}
  14. echo "array as ${count} elementes "
  15. display_menu () {
  16.   opt=1
  17.   while [ $opt -ne 0 ] ; do
  18.   echo "###########################"
  19.         # agora vou gerar o menu de forma dinamica
  20.         for (( i = 0 ; i < ${count} ; i++ )) ; do
  21.             echo "# ${i} - ${title_array[$i]}"
  22.         done
  23.  
  24.   echo "# x - Sair deste menu     #"
  25.   echo "###########################"
  26.   echo "# Escolha uma opçao       #"
  27.   echo "###########################"
  28.   read opt
  29.     case $opt in
  30.  
  31.         #if [  $opt -eq $i ]  ; then
  32.         #    ${i} ) ${title_array[$i]} ;;
  33.         #fi
  34.         $opt ) echo ${func_array[$opt]} ;;
  35.  
  36.         x) exit     ;;
  37.         *) echo "invalid Option "
  38.     esac
  39.  
  40.   done
  41. }
  42.  
  43. display_menu
  44.  
RAW Paste Data