[Top][All Lists]

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

Re: Bash/readline enhancement: wish to pre-set initial value of input te

From: Chris F.A. Johnson
Subject: Re: Bash/readline enhancement: wish to pre-set initial value of input text
Date: Wed, 09 Jul 2008 21:19:57 +0000
User-agent: slrn/ (Debian)

On 2008-07-08, Richard Neill wrote:
> Dear All,
> When using read, it would be really neat to be able to pre-fill the form
> with a default (or previous) value.
> For example, a script which wants you to enter your name, and thinks
> that my name is Richard, but that I might want to correct it.
> Alternatively, this would be useful within a loop, to allow correction
> of previously-entered text, without fully typing it again.
> So, I propose an extra option, -i, to read, which will set the initial
> value of the text following the prompt.

     I like that idea.

     In the meantime, I use:

history -s "$DEFAULT"
read -ep "Enter name (up arrow for '$DEFAULT'): " name

> For example,
> ------------------------
> #!/bin/bash
> read -e -p 'Enter your name: ' -i 'Richard' NAME
> echo "Hello, $NAME"
> ------------------------
> This would print:
>    Enter your name: Richard
> I would then be able to edit the part after the prompt, and change it to:
>    Enter your name: R. Neill
> This would then print:
>    Hello, R. Neill
> It is equivalent to the following in PHP/HTML:
><? $name='Richard'; ?>
> Enter your name: <INPUT TYPE="text" NAME="name" SIZE=30 VALUE="<?=$name;?>">
> An alternative syntax might be to make use of stdin for the read
> command, eg:
>   echo 'Richard' | read -e -p 'Enter your name: ' NAME
> though I think I prefer the -i.
> I hope you like this idea. Thanks very much for your help.
> Richard

reply via email to

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