Here’s the sample code:
user$ touch file.txt
user$ mate !$
“mate” is calling textmate text editor, and that second command opens the previously created file.txt. what is this !$ syntax? what does ! do? what does $ do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is a shell feature called in various shells history expansion or history substitution.
Words starting with an exclamation mark are replaced with words from previously executed commands. Which words and which commands, it depends on the rest of the word.
In this particular example the dollar sign refers to the last word of a command, and since there is no other character between ‘!’ and ‘$’ the referenced command is the previous one, so !$ gets replaced with the last argument of the prevoius command.
What other command and word specifiers exist differ somewhat between shells.