Skip to content

Instantly share code, notes, and snippets.

@shellscriptx
Created June 2, 2018 14:45
Show Gist options
  • Save shellscriptx/8dd636b7c14c9c975018998901b29f3d to your computer and use it in GitHub Desktop.
Save shellscriptx/8dd636b7c14c9c975018998901b29f3d to your computer and use it in GitHub Desktop.
#!/bin/bash
  
# Loop infinito.
while :; do
    # Limpa a tela.
    clear

    # menu
    cat << _eof
## MENU ##

1 - Exibir hora
2 - Exibir data
3 - Sair
_eof

    # Aguarda uma tecla.
    read -n1 -p 'Opcao: ' ch
    echo

    # Trata o caractere lido.
    case $ch in
        1)  printf 'Hora: %(%H:%M)T';;                  # Hora
        2)  printf 'Data: %(%d/%m/%Y)T';;               # Data
        3)  printf 'Saindo...\n'; break;;               # Finaliza o loop.
        *)  printf '\033[0;31mOPCÃO INVÁLIDA\033[0;m'
    esac
    echo
    sleep 2
done
# FIM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment