In the Terminal I can use !!
which will reference my previous command.
Is it possible to use this in an alias? I have tried it, but what happens is that the double exclamation marks are interpreted literally.
What I want to have possible is:
- I enter some command
- I type an alias that will include what was entered in step 1
If there is a solution using scripts that is also acceptable.
Best Answer
The command that lists the last executed command is
fc -nl -1
. Using output substitution , we can add more parameters to the same contentQuoting , however, may be an issue with this approach
A very nice feature of
fc
is that if you just runfc
command by itself, it will open text editor specified inFCEDIT
variable (which you probably want stored in~/.bashrc
) and the contents of the line will be your last command. For your ease, I suggest you usenano
as your text editor, but if you knowvim
- even better.For example, what if I need to edit
qdbus org.ayatana.bamf /org/ayatana/bamf/matcher org.ayatana.bamf.matcher.ActiveWindow
Huge line, right ? But withfc
, I can openvim
and edit/org/ayatana/bamf/matcher
, save, exit and it will run.