bug-bash
[Top][All Lists]
Advanced

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

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


From: Richard Neill
Subject: Bash/readline enhancement: wish to pre-set initial value of input text
Date: Tue, 08 Jul 2008 04:17:29 +0100
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

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.

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]