[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prefilling keyboard buffer

From: Bob Proulx
Subject: Re: prefilling keyboard buffer
Date: Sat, 16 Jun 2007 12:02:33 -0600
User-agent: Mutt/1.5.9i

greno wrote:
> How can the keyboard buffer be prefilled with an answer for a read command?
> I want to prompt the user with a question using the read command and then
> suggest an answer that they could backspace over and change if necessary.  

In order to do this a helper application is usually needed such as
'dialog' or 'whiptail' or some such.  The helper application
implements full terminal editing in order to achive that behavior.
Those work fine but create a dependency that personally would avoid if
I were writing a script to be used on multiple systems.  If I know
that I will always have dialog available (such as on Debian systems)
then I use it.  But on HP-UX or AIX for counter examples then
requiring dialog to be present is an extra dependency that I would
rather avoid.

I recommend a simpler method.  I recommend placing the default value
in the prompt.  If the user simply enters without entering any data
then use the default value.  If the user enters anything then use
whatever the user entered.  This is in some ways better because the
default value is always present even if the user selects a non-default

I will include an example to illustrate the technique.



printf "Enter a value [$defaultvalue]: "
read value
if [ -z "$value" ]; then

echo "The value is \"$value\""

exit 0

reply via email to

[Prev in Thread] Current Thread [Next in Thread]