Enviado em 11/01/2024 - 16:00h
Este é um esboço de um menu checklist sem dialog ou similares.#!/bin/sh
: '
Two read functions for Bourne Shell (ueliton@disroot.org 28/07/23)
usage;
mini_read -t 3 -n 3 myVar
-n nchars return after reading NCHARS characters rather than waiting for a newline.
Just work with -s arg.
-t time out and return failure if a complete line of input is not read within TIMEOUT seconds.
-s do not echo input coming from a terminal
'
mini_read () {
#enquanto total args maior que 0
while [ $# -gt 0 ]; do
# caso primeiro arg
case "$1" in
-t)
MRTIME=$2 shift 2
;;
-n)
MRCOUNT=$2 shift 2
;;
-s)
MRSUPRE=$1 shift
;;
*)
if [ $# -eq 1 ]; then
MRVAR_NAME=$1
shift
else
echo "Invalid parameter: $1"
exit 1
fi
;;
esac
done
MRLAST_ARG=${!#}
eval "MRVAR=\$$MRLAST_ARG"
eval "${MRVAR_NAME}=\$MRVAR"
if [ -z "$MRTIME" ]; then
MRTIME=300
elif [ -z "$MRCOUNT" ]; then
MRCOUNT=300
fi
mrback_ground () {
(
sleep 1s
for MRLOOP in $(seq $MRTIME -1 0); do
MRPIDF=$(ps ax -o pid=,args=|grep "dd bs=1 count=$MRCOUNT"|grep -v 'grep'|head -n 1|grep -o -E '([0-9]{2,6})')
if [ -z "$MRPIDF" ]; then
MRLOOP=0
elif [ "$MRLOOP" -eq 0 ]; then
kill -s PIPE $MRPIDF >/dev/null 2>&1
kill -15 $MRPIDF >/dev/null 2>&1
fi
sleep 1s
done
)
}
mrback_ground </dev/null &>/dev/null &
MRFPID=$(echo "$!"|grep -o -E '([0-9]{2,6})')
unset MRINPUT_READ
if [ ! -z "$MRSUPRE" ]; then
stty -echo
fi
stty raw
MRINPUT_READ=$(dd bs=1 count="$MRCOUNT" 2>/dev/null)
stty -raw
stty echo
eval ${MRVAR_NAME}=$MRINPUT_READ
MRRPID=$(ps ax -o pid=|grep -o "$MRFPID")
if [ -z "$MRINPUT_READ" ] && [ ! -z "$MRRPID" ]; then
kill -s PIPE $MRFPID >/dev/null 2>&1
kill -15 $MRFPID >/dev/null 2>&1
printf "\n"
exit 1
else
printf "\n"
fi
}
#mini_read -n 2 -t 30 test
check_list(){
options(){
case $key in
A|a|1) case $Acheck in
A|a|1) Acheck="";;
*) Acheck="A";;
esac;;
B|b|2) case $Bcheck in
B|b|2) Bcheck="";;
*) Bcheck="B";;
esac;;
C|c|3) case $Ccheck in
C|c|3) Ccheck="";;
*) Ccheck="C";;
esac;;
D|d|4) case $Dcheck in
D|d|4) Dcheck="";;
*) Dcheck="D";;
esac;;
E|e|5) case $Echeck in
E|e|5) Echeck="";;
*) Echeck="E";;
esac;;
x|X) key="fim";;
esac
}
options
}
menu_list(){
a_check(){
if [ -z $Acheck ];then echo "( )";else echo "(x)";fi
}
b_check(){
if [ -z $Bcheck ];then echo "( )";else echo "(x)";fi
}
c_check(){
if [ -z $Ccheck ];then echo "( )";else echo "(x)";fi
}
d_check(){
if [ -z $Dcheck ];then echo "( )";else echo "(x)";fi
}
e_check(){
if [ -z $Echeck ];then echo "( )";else echo "(x)";fi
}
printf "\n Marque o que deseja digitando as letras referentes:
$(a_check) A. opt1
$(b_check) B. opt2
$(c_check) C. opt3
$(d_check) D. opt4
$(e_check) E. opt5
Digite X para sair\n"
}
until [ "$key" = fim ];do
clear
menu_list
mini_read -s -n 1 key
check_list
if [ "$key" = fim ]; then
break
fi
done
Atualizar o macOS no Mac - Opencore Legacy Patcher
Crie alias para as tarefas que possuam longas linhas de comando - bash e zsh
Criando um gateway de internet com o Debian
Configuração básica do Conky para mostrar informações sobre a sua máquina no Desktop
Aprenda a criar músicas com Inteligência Artificial usando Suno AI
Instalando Zoom Client no Ubuntu 24.04 LTS
Instalando Zoom Client no Fedora 40
Instalando Navegador Firefox no Debian 12
Bloqueando propagandas no Youtube e outros sites com o uBlocker Origin
Configurando static ipv6 em placa de rede eth0[DUVIDA] (1)
Sistema da Coréia do Norte - Red Star OS (59)
Comando interno CD não funciona (16)
Dificuldade em ler binário (12)
Em que pasta/arquivo ficam as configurações das janelas em derivados d... (2)