1

What does this command do?

!g++ 

For the history command:

!12 

It runs command #12 of the history, but what about g++, or another:

!cat filename 
3
  • Wrong site. StackOverflow is for programming questions, not usage. Commented Feb 12, 2016 at 0:37
  • gnu.org/software/bash/manual/bashref.html#Event-Designators Commented Feb 12, 2016 at 0:40
  • @tink Using command line is not exactly programming... but thanks anyway. Commented Feb 12, 2016 at 0:45

1 Answer 1

2

See the Bash manual, "Event Designators":

!string

Refer to the most recent command preceding the current position in the history list starting with string.

This means that !g++ runs the last command that began with g++, calling the GNU C++ compiler:

$ g++ -o myprog -flto -O3 foo.o bar.o baz.o -lgfortran ... (g++ does its job here) ... $ vim test ... (other commands) ... $ !g++ g++ -o myprog -flto -O3 foo.o bar.o baz.o -lgfortran <-- same command as before 

!cat filename, on the other hands, doesn't make a lot of sense as it's already a complete command. Unless there was a super complicated pipe after that command the last time, of course, which the event designator would then repeat.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.