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 value. I will include an example to illustrate the technique. Bob #!/bin/sh defaultvalue=42 printf "Enter a value [$defaultvalue]: " read value if [ -z "$value" ]; then value=$defaultvalue fi echo "The value is \"$value\"" exit 0 _______________________________________________ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash