MichaelScott
MichaelScott

Reputation: 387

echo a message while waiting for user input shell

Is it possible to echo a variable name while waiting for a user input in a shell script? My idea was to run down a timer while waiting for an input. If an input was made during that time do sth. If not exit. So far I got for the sh-shell:

    read -t 5 -p "start?" inputname

But this option does not print anything while waiting. Any suggestions?

Thanks guys and have a nice weekend!

Upvotes: 0

Views: 170

Answers (1)

MichaelScott
MichaelScott

Reputation: 387

ok I fixed it with a little turn around:

    #!/bin/bash

    printf "INFO: Press any key to continue...  "
    SEC=3
    INPUT="n"
    while [ $SEC -gt 0 -a "$INPUT" == "n" ]; do
    printf "\b%d" "$SEC"
    read -t 2 -s -n1 INPUT 

    SEC=`expr $SEC - 1` 

    done

Upvotes: 1

Related Questions