Advertisement
LightProgrammer000

Menu [array]

Jul 11th, 2021
1,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##########
  4. # FUNCAO #
  5. ##########
  6.  
  7. 1()
  8. {
  9.     clear
  10.     echo -e "\033[01;31m# 1 \n\033[01;37m"
  11.     read -p "|| ENTER ||"
  12. }
  13.  
  14. 2()
  15. {
  16.     clear
  17.     echo -e "\033[01;32m# 2 \n\033[01;37m"
  18.     read -p "|| ENTER ||"
  19. }
  20.  
  21. 3()
  22. {
  23.     clear
  24.     echo -e "\033[01;33m# 3 \n\033[01;37m"
  25.     read -p "|| ENTER ||"
  26. }
  27.  
  28. 4()
  29. {
  30.     clear
  31.     echo -e "\033[01;34m# 4 \n\033[01;37m"
  32.     read -p "|| ENTER ||"
  33. }
  34.  
  35. 5()
  36. {
  37.     clear
  38.     echo -e "\033[01;35m# 5 \n\033[01;37m"
  39.     read -p "|| ENTER ||"
  40. }
  41.  
  42. #####################
  43. # Controle de fluxo #
  44. #####################
  45.  
  46. # Apresentacao
  47. apresentacao()
  48. {
  49.     clear
  50.     echo -e "\033[01;33m###################################\033[01;37m"
  51.     echo -e "\033[01;32m Desenvolvido por DarProgrammer000 \033[01;37m"
  52.     echo -e "\033[34;5m # LightProgrammer000           \033[0m"
  53.     echo -e "\033[01;33m###################################\033[01;37m"
  54.     echo ""
  55. }
  56.  
  57. # Montagem de menu principal
  58. controle_menu()
  59. {
  60.     # Montagem de um array list
  61.     declare -a arr=("1"
  62.                 "2"  
  63.             "3"
  64.             "4"
  65.             "5"  
  66.             "")
  67.        
  68.     # Tamanho do vetor: ${#arr[@]}
  69.     # Estrutura em loop (estilo C))
  70.     # $i(indice): ${arr[$i]} (conteudo na lista)
  71.  
  72.     echo -e "\033[01;35m# MENU PRINCIPAL \033[01;37m"
  73.    
  74.     for (( i=0; i < ${#arr[@]} - 1; i++))
  75.     do
  76.         echo -e "\033[01;32m # [$((i+1))]: ${arr[$i]} \033[01;37m"
  77.     done
  78.  
  79.     echo -e "\033[01;31m # [0]: Sair \n\033[01;37m"
  80.     echo -n -e "\033[01;37m# Opc.: \033[01;37m"
  81.     read opc
  82. }
  83.  
  84. # Estrutura em escolha
  85. escolha()
  86. {
  87.     case $opc in
  88.     1)  1;;
  89.     2)  2;;
  90.     3)  3;;
  91.     4)  4;;
  92.     5)  5;;
  93.     0)   ;;
  94.     *)   ;;
  95.     esac
  96. }
  97.  
  98. # Controle de fluxo
  99. Programa()
  100. {
  101.     while ((1))
  102.     do
  103.         apresentacao
  104.         controle_menu
  105.         escolha
  106.            
  107.         if (( opc == 0 ))
  108.         then
  109.             break
  110.         else
  111.             continue
  112.         fi
  113.     done
  114. }
  115.  
  116. ######################
  117. # Programa principal #
  118. ######################
  119.  
  120. # Execucao do programa
  121. Programa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement