简体   繁体   中英

What does !!:2 mean in Mac or Linux?

Today I saw a command in Mac:

touch !!:2/{f1.txt, f2.txt}

I know the use of touch command but what does !!:2 does in this command. I don't have Mac and tried in Linux It is giving some weird output. If anyone could explain more expression like this it would be great.

touch updates file timestamp (to current time, given no arguments)

!! is 'History expansion' operation, retrieving previous command from bash history log in this form (two exclamation dots), alias for '!-1'

:2 is word specifier, retrieving 2nd command argument. Eg if previous history command was ls -l /tmp , !!:2 will render to '/tmp'

{f1.txt,f2.txt} is called 'Brace expansion'. Brace expansion requires single word string without unescaped white spaces (it's definitely a typo in the question). For example, foo{bar,baz} will be expanded to 'foobar foobaz'

So, let's assume we run bash command

ls -l /tmp

Now, touch !!:2/{f1.txt,f2.txt} will produce

touch /tmp/f1.txt /tmp/f2.txt

https://tiswww.case.edu/php/chet/bash/bashref.html

!! refers to the previous command. This is a synonym for '!-1'.

:2 refers to the second argument.

So for example :

echo "content" > foo
cp foo bar
cat !!:2

Displays the content of bar. !!:2 is the second argument of the previous command. Which one was it in your example?

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