Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does !!:2 mean in Bash?

Tags:

bash

I was watching the this video tutorial and around the 1:40 mark the author issues the following command. It creates two files, under the recently created folder.

touch !!:2/{package.json,index.js}

Can someone please explain what !!:2 means? and why it didn't create the two files under all the folders?

like image 781
Zuhaib Avatar asked Nov 22 '25 12:11

Zuhaib


1 Answers

in bash you can use !! to repeat the previous command line. A typical usage is:

do some command that needs root permissions
# this fails, so:
sudo !!

which will expand to:

sudo do some command that needs root permissions

the expression !!:2 means: take the third (0-based indexing) word from the previous command line.

example to illustrate:

$ echo these are some words in a sentence
these are some words in a sentence
$ echo !!:2
echo are
are

NOTE that this is extremely error prone, especially with the 0-based indexing

like image 162
Chris Maes Avatar answered Nov 24 '25 03:11

Chris Maes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!