38 minutes ago · Tech · hide

I have much bigger issues to be concerned with than saving a few seconds of typing with obscure bash features. But precisely because I have bigger issues on my plate, it’s fun to take a moment and solve some little tangible problem. The shell !$ saves the last part of the latest command. (Mnemonic: bang often refers to commands, such as !! to redo the previous command, and cash often refers to the last of something, such as the end of a line in a regular expression.) This comes in handy, for example, when you copy a file to a directory and then want to cd into that directory. cp myfile /big/long/path cd !$ The !$ variable is fragile, however. The sequence of commands cp myfile /big/long/path ls cd !$ won’t work because after running ls the variable !$ now contains “ls” rather than “/big/long/path”. There are two ways to fix this. In the previous example you could change the last command to cd !-2:$ This says go back two commands (!-2) and extract (:) the last argument ($). Another…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town