!! is a shortcut for !-1, referring to the previous command. Colon : precedes the modifier q, which lets the expansion quote the substituted words with single quotes to prevent further substitutions.
Example run
$ uname -r # run your command
4.10.0-35-generic
$ echo !!:q | xclip -sel clip # copy the previous command to clipboard
echo 'uname -r' | xclip -sel clip # this line shows what’s done
$ xclip -sel clip -o # print clipboard content (just for testing)
uname -r
$ $(xclip -sel clip -o) # run command stored in clipboard (just for testing)
4.10.0-35-generic
You can use
bash
’s History Expansion, to copy the previous command line to your clipboard without performing command substitution, expansions etc. do:!!
is a shortcut for!-1
, referring to the previous command. Colon:
precedes the modifierq
, which lets the expansion quote the substituted words with single quotes to prevent further substitutions.Example run
To simplify this you can create an
alias
or set a keyboard shortcut in the settings. Readman bash
/HISTORY EXPANSION andman history
to learn more about history expansion.