Re: [SLUG] bash - moving up a notch

From: Ian C. Blenke (icblenke@nks.net)
Date: Wed Oct 05 2005 - 21:54:52 EDT


Mike Branda wrote:
> Basically, I dont want to have to answer the same exact questions
> dozens of times. I want to do it once by hand, record the questions and
> my answers, look for what's unique in each question with the outer
> script and insert the proper answer stored in a variable form. All
> automated after the first one by hand. The alternative would be to hack
> the config file not to ask the questions (input reads) and just set it
> to the answers although there are a lot of if's to handle the returned
> possibilities.
>
> If the idea (auto filling the answers) is too clunky it's o.k. but I was
> wondering if it's even possible.
>
The simplest method is to print the default value on the line above, and
if the user hits return merely use that default value:

    $default_color=Red
    echo Default value is: $default_color
    echo -n Enter a color:
    read color
    if [ -z $color ]; then
       color=$default_color
    fi

Or you could do something tricky like:

    $default_color=Red
    echo -n "Enter a color: $default_color^MEnter a color: "
    read color
    if [ -z $color ]; then
       color=$default_color
    fi

The problem with this method is that you hint to the user that they can
"edit" that value partially (which isn't true), and the user will
usually try to use cursor keys to do so (which won't work).

When you give users a hint like this, it might be wise to use something
that acts as a readline wrapper to display that default value while
asking for input. There is bound to be something simple out there that
does just this.

Alternatively, you could put together a quick "dialog" screen for
entering data with default values.

Hope this helps,

- Ian C. Blenke <icblenke@nks.net> <ian@blenke.com> http://ian.blenke.com

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:57:48 EDT