简体   繁体   中英

What does !!:2 mean in 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM