This is one I constantly forget, but $_ in a bash shell (and other languages like Perl and I know it’s in Windows Powershell but may have a different usage) is a special parameter, it gives the last argument to the previous command. This comes in handy all the time when editing and executing on the same thing. For example, here I’m working with a python script:

[kevinkingsbury@host:~]$ python ~/code/python/python-example-file/ 
[kevinkingsbury@host:~]$ echo $_
[07:46][kevinkingsbury@host:~]$ vi $_

You see that the $_ gets set to the file, so I can preform different commands on that file just by passing the variable, comes in handy with long paths.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.