Unix Shell - History echo trick

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2007 > History echo trick





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 History echo trick
Gonsolo

2007-08-24, 7:23 am

Hi!

I just wanted to make sure to post a little trick I just invented:
If you have to repeat a complicated command you can type control-r in
gnu bash and then enter some characters of the command. The history
is automatically searched for all commands containing these
characters.

The command I use doesn't have any unique words so it isn't easy to
find
it in history. The trick I came up with is:
<complicated command> ; echo gnorz

This way I can type control-r gnorz and voila, Ii found my command
again.
This can be seen as a poor man's alias.

If this is old, well-known and boring, please forgive me.

Cyrus Kriticos

2007-08-24, 1:24 pm

Gonsolo wrote:
>
> I just wanted to make sure to post a little trick I just invented:
> If you have to repeat a complicated command you can type control-r in
> gnu bash and then enter some characters of the command. The history
> is automatically searched for all commands containing these
> characters.
> [...]
> The trick I came up with is:
> <complicated command> ; echo gnorz
>
> This way I can type control-r gnorz and voila, Ii found my command
> again.
> This can be seen as a poor man's alias.
>
> If this is old, well-known and boring, please forgive me.


If I have to repeat a complicated command I move the cursor to end of line
(CTRL+E) and press

CTRL+U

to kill backward from point to the beginning of line.

Everytime I need the killed line I press

CTRL+Y

> [...] voila [...]


--
Best | "Was bekommt man/frau, wenn man/frau Software kauft?
regards | Nichts außer einem Haufen Nullen und Einsen."
Cyrus | -- aus d. Lizenzvereinbarung von Spybot Search&Destroy
Chris F.A. Johnson

2007-08-28, 1:20 am

On 2007-08-24, Cyrus Kriticos wrote:

> If I have to repeat a complicated command I move the cursor to end of line
> (CTRL+E) and press


Or just use Alt-K.

> CTRL+U
>
> to kill backward from point to the beginning of line.
>
> Everytime I need the killed line I press
>
> CTRL+Y
>
>



--
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
Cyrus Kriticos

2007-08-28, 1:20 am

Chris F.A. Johnson wrote:
> On 2007-08-24, Cyrus Kriticos wrote:
>
>
> Or just use Alt-K.


CTRL+K ?
[vbcol=seagreen]

--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Chris F.A. Johnson

2007-08-28, 7:21 am

On 2007-08-28, Cyrus Kriticos wrote:
> Chris F.A. Johnson wrote:
>
> CTRL+K ?


CTRL+K clears from the current position to the end of the line;
Alt+K (or ESC K) clears the entire line.

>



--
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
Chris

2007-08-28, 7:21 am

On 28 Aug., 11:25, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> On 2007-08-28, Cyrus Kriticos wrote:
>
>
>
>
>
> CTRL+K clears from the current position to the end of the line;
> Alt+K (or ESC K) clears the entire line.
>
>
>
>
>
>
> --
> 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


If you set:

set -o vi

Then you can iterate your last commands by using Strg+k

Matthias Buelow

2007-08-28, 7:21 am

Chris wrote:

> Then you can iterate your last commands by using Strg+k


No, he cannot. Vi mode is using the hjkl keys (just as vi does). Ctrl+k
is bound to the emacs function (kill to end-of-line) in bash's vi mode,
too (because vi doesn't use it otherwise).
Chris

2007-08-28, 7:21 am

On 28 Aug., 13:12, Matthias Buelow <m...@incubus.de> wrote:
> Chris wrote:
>
> No, he cannot. Vi mode is using the hjkl keys (just as vi does). Ctrl+k
> is bound to the emacs function (kill to end-of-line) in bash's vi mode,
> too (because vi doesn't use it otherwise).


Sry my mistake, this happens if you do two things at twice...

pgas

2007-08-28, 1:24 pm

On Aug 28, 12:25 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com>
wrote:
>
> CTRL+K clears from the current position to the end of the line;
> Alt+K (or ESC K) clears the entire line.
>

maybe it's a personal setting?
the manual here doesn't seem to document a binding and:

bind -P | grep whole
kill-whole-line is not bound to any keys

Chris F.A. Johnson

2007-08-28, 7:21 pm

On 2007-08-28, pgas wrote:
> On Aug 28, 12:25 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com>
> wrote:
> maybe it's a personal setting?
> the manual here doesn't seem to document a binding and:
>
> bind -P | grep whole
> kill-whole-line is not bound to any keys


You're right; I had forgotten that I had added that to ~/.inputrc:

"\ek": kill-whole-line


--
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
jellybean stonerfish

2007-08-29, 1:15 am

On Fri, 24 Aug 2007 04:27:40 -0700, Gonsolo wrote:

> Hi!
>
> I just wanted to make sure to post a little trick I just invented:
> If you have to repeat a complicated command you can type control-r in
> gnu bash and then enter some characters of the command. The history
> is automatically searched for all commands containing these
> characters.
>
> The command I use doesn't have any unique words so it isn't easy to
> find
> it in history. The trick I came up with is:
> <complicated command> ; echo gnorz
>
> This way I can type control-r gnorz and voila, Ii found my command
> again.
> This can be seen as a poor man's alias.
>
> If this is old, well-known and boring, please forgive me.


You can also do
<complicated command> ; # gnorz
This seems to work, and doesn't ouptut "gnorz" to your terminal. Leaving
the command's output pure.


stonerfish
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com