bash: how to echo to the prompt without executing
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > bash: how to echo to the prompt without executing




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    bash: how to echo to the prompt without executing  
Berk Birand


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-27-06 12:29 PM

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






[ Post a follow-up to this message ]



    Re: bash: how to echo to the prompt without executing  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-27-06 12:29 PM

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





[ Post a follow-up to this message ]



    Re: bash: how to echo to the prompt without executing  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-27-06 06: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....shell.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





[ Post a follow-up to this message ]



    Re: bash: how to echo to the prompt without executing  
Berk Birand


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-28-06 12:21 AM

On Wed, 27 Dec 2006 12:13:17 -0500, Chris F.A. Johnson wrote:

> On 2006-12-27, Berk Birand wrote:
[vbcol=seagreen] 
>
>    See also:
> <http://groups.google.com/group/gnu....c2?dmode=source>[/v
bcol]

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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:37 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register