|
Home > Archive > Unix Shell > December 2006 > bash: how to echo to the prompt without executing
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
bash: how to echo to the prompt without executing
|
|
| Berk Birand 2006-12-27, 7:29 am |
| Hi,
I had posted the following question to gnu.bash, but couldn't get an
answer. I then found out about this newsgroup, and figured I could try it
here.
I know the subject sounds really weird, but that's the best I could
do to summarize what I want in one line. I am looking for a way to echo
some string to the bash prompt without actually executing it. The string
should be displayed after PS1, and the user should be able to edit it
using the standard command-line editing keys. Once s/he is done, pressing
RETURN will finally send it to the shell, just like as usual. This can be
from within a shell script or function, or even in C or Perl.
Can this be done at all? I had looked at some escape sequences, but I
couldn't find anything useful.
Any help would be appreciated,
Berk
--
Posted via a free Usenet account from http://www.teranews.com
| |
| Stephane CHAZELAS 2006-12-27, 7:29 am |
| 2006-12-27, 04:13(-05), Berk Birand:
[...]
> I had posted the following question to gnu.bash, but couldn't get an
> answer. I then found out about this newsgroup, and figured I could try it
> here.
>
> I know the subject sounds really weird, but that's the best I could
> do to summarize what I want in one line. I am looking for a way to echo
> some string to the bash prompt without actually executing it. The string
> should be displayed after PS1, and the user should be able to edit it
> using the standard command-line editing keys. Once s/he is done, pressing
> RETURN will finally send it to the shell, just like as usual. This can be
> from within a shell script or function, or even in C or Perl.
>
> Can this be done at all? I had looked at some escape sequences, but I
> couldn't find anything useful.
[...]
Don't know about bash, with zsh, you could do:
print -rz -- "$text"
Additionally you can define new /widgets/ that are zsh functions
you can write to bind actions on keys (for instance, it can also
be events on other sources of input). In those functions
$BUFFER, $LBUFFER, $RBUFFER, $CURSOR are read-write variables
that reflect the current editing buffer.
With any shells, on some systems there exist a tty ioctl (like
TIOCSTI) that allows you to write some data to the input queue
so that they arrive to the applications as if they had been
typed by the user.
--
Stéphane
| |
| Chris F.A. Johnson 2006-12-27, 1:16 pm |
| On 2006-12-27, Berk Birand wrote:
> Hi,
>
> I had posted the following question to gnu.bash, but couldn't get an
> answer. I then found out about this newsgroup, and figured I could try it
> here.
>
> I know the subject sounds really weird, but that's the best I could
> do to summarize what I want in one line. I am looking for a way to echo
> some string to the bash prompt without actually executing it. The string
> should be displayed after PS1, and the user should be able to edit it
> using the standard command-line editing keys. Once s/he is done, pressing
> RETURN will finally send it to the shell, just like as usual. This can be
> from within a shell script or function, or even in C or Perl.
>
> Can this be done at all? I had looked at some escape sequences, but I
> couldn't find anything useful.
history -s $string
read -ep "$PS1 (press up arrow to edit $string): "
eval "$REPLY"
See also:
<http://groups.google.com/group/gnu....c2?dmode=source>
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Berk Birand 2006-12-27, 7:21 pm |
| On Wed, 27 Dec 2006 12:13:17 -0500, Chris F.A. Johnson wrote:
> On 2006-12-27, Berk Birand wrote:
>
> See also:
> <http://groups.google.com/group/gnu....c2?dmode=source>
This patch seems awfully useful. Do you know if it has been incorporated
in the new versions of bash? I looked through the NEWS file for any
changes made to the read builtin, but couldn't find anything that looks
similar.
Thanks for the reply,
Berk
--
Posted via a free Usenet account from http://www.teranews.com
|
|
|
|
|