Re: Skriptfrage: Benutzereingabe mit Timeout
Hi Michael,
Am 28.11.2013 13:08, schrieb Michael Stummvoll:
> > #!/bin/bash
> >
> > timeout=10
> > {
> > for ((i=timeout; i>=0; i--)); do
> > printf "$(tput sc)\r[%02d]$(tput rc)" $i
> > sleep 1
> > done &
> > } 2> /dev/null
> > printf " Input? "
> > read -t $timeout.1 input || printf "\n"
> > kill $! &>/dev/null
> > : ${input:=defaultvalue}
> > printf "Hello %s!\n" $input
>
..in der Tat - die Idee ist an sich echt gut, aber der Hack trotzdem fies ;)
In 9 von 10 gehts, aber manchmal kommt sowas raus:
$ bash test
[09]Input? ab
Hello ab!
test: Zeile 15: 23156 Beendet for ((i=timeout; i>=0; i--))
do
printf "$(tput sc)\r[%02d]$(tput rc)" $i; sleep 1;
done
Das ist natürlich nicht ganz ideal. Muß mal noch rumbasteln damit... Aber trotzdem danke. Was man alles anstellen kann mit der Bash ;)
--
Andre Tann
Reply to: