Basically it has a use in yanking previous (command's) arguments.
For instance, if the following command is issued:
echo Hello, world how are you today?
then, Hello,
will be the first argument, and today?
the sixth, that is the last one; meaning it can be referenced by typing:
Alt+6 followed by Ctrl-Alt-6
Ctrl is traditionally denoted as a hat character ^
prepended to keys names, and Alt as M-
that is Meta prefix.
So the above shortcut can be redefined as ^My
to yank.
Also, there is hats substitution shortcut in the command line:
echo Hello, world!
^Hello^Bye
Bye, world!
to substitute the previous command's first matched string, meaning:
Hello, world! Hello, people!
^Hello^Bye
would result in:
Bye, world! Hello, people!
leaving the second match (hello
) unchanged.
Note: Do not leave space between hats, or the operation won't work.
The above is just a shortcut for:
!:s/Hello/Bye
event-level(*) substitution for the first found (matched) string in the previous command, while prefixing the first part with the g
switch will apply to the whole line globally:
echo Hello, world! Hello, people!
!:gs/Hello/Bye
Bye, world! Bye, people!
as usually being done in other related commands such as sed
, vi
, and in regex
(regular expression) - a standart way to search (match string).
No, you can't do !:sg/Hello/Bye
or !:s/Hello/Bye/g
here, that's the syntax!
- ! is for events; event might be understood as command output or operation done in the commands history.
That's what I understood by using it myself and trying things on my own from what I read from various sources including manual pages, blogs, and forums.
Hope it will shed some light into mysterious ways of bash
, the Bourne-Again shell (a play on sh
shell, which itself is called Bourne shell after its inventor's last name), what is default shell in many distributions including servers (server OS's).
bind -lp
and looking at the current bindings. – Halflight