Assume that the history list contains the command e='echo a b c'
and then $e
.
How to refer to the command $e
using the history expansion feature of bash?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityAssume that the history list contains the command e='echo a b c'
and then $e
.
How to refer to the command $e
using the history expansion feature of bash?
Here is an alternative you can set an alias for:
eval `history |awk '/^ [0-9]* [$]/{print $2}'|tail -n 1`
It searches the history for the last command starting with $
and evaluates the result. Although, it will not work with multiline commands.
I would suggest using Ctrl+R, typing $
, and cycling through previous commands matching $
.
!?$
, but it searches$
anywhere in the command, not only in the beginning. So if there is some other command with$
e.g.echo "$e"
coming after$e
..., you get that.