Meruemu
Meruemu

Reputation: 611

What does ./!$ mean in Linux?

A noobie Linux learner here.

I created a python script and chmod 700 filename.py, when I was going to using ./filename.py, my instructor came and use ./!$ to run the file.

What does the ./!$ that actually mean? I couldn't google it out. I'd greatly appreciate for a link of cheatsheet for the similar commend too.

Thanks in advance.

Upvotes: 6

Views: 1746

Answers (2)

Aif
Aif

Reputation: 11220

Fully agree with Michael Berkowski's comment. !$ refers to the last argument from the previous bash command. For instance, if you type echo hello world then !$ would expand to "world".

In your case, the !$ is expanded into "filename.py". The command becomes strictly the same as above: ./filename.py.

Upvotes: 2

Jossie Calderon
Jossie Calderon

Reputation: 1425

Suppose I just ran a command python test.py. This was my last command I entered into the shell. However, its argument was test.py.

Remembering that ./ refers to the current working directory, when I type ./!$ I get the following output:

$ ./!$
./test.py
./test.py: line 1: import: command not found
./test.py: line 2: $'\r': command not found
./test.py: line 3: syntax error near unexpected token `('
'/test.py: line 3: `df = pd.DataFrame([

By context clues my last argument was used as the !$.

If I enter several arguments such as python test.py test2.py I get:

$ ./!$
./test2.py
./test2.py: line 1: import: command not found
Unable to initialize device PRN

Confirming my intuition.

Upvotes: 2

Related Questions