News for hackers. Stuff that matters.
Re:Ask HN: Teach me something new by senjin on Saturday April 30, 2022 @10:23AM (#31216281)
I use !$ multiple times every day but you just helped me make the connection to try !^ for the first argument and I think I'm going to start using that as well. Thanks!
Re:Ask HN: Teach me something new by schoen on Saturday April 30, 2022 @02:45PM (#31218198)
There is also "!!" for the entire prior command line. Someone elsewhere in this thread mentioned the usefulness of

  sudo !!
for "run the entire previous command under sudo".

Another example could be

  echo "!!" > myscript
for "save the previous command into the file myscript".
Re:Ask HN: Teach me something new by senjin on Sunday May 01, 2022 @09:50AM (#31224999)
I also use cat `which !!` every once in a while
Re:Ask HN: Teach me something new by aasasd on Saturday April 30, 2022 @09:02PM (#31221071)
At least in zsh, there are also !:1 for the first argument, et cetera with the rest of natural numbers, and something like !:* for all the arguments without the command.

The generic form is !n:m for n-th last command line and m-th argument, with an omitted n being a shortcut for the last line.

Not sure if all of this works the same in bash.

Re:Ask HN: Teach me something new by senjin on Sunday May 01, 2022 @09:52AM (#31225011)
I use zsh so this is also going in my toolbox. I think I've reached for !:* in the past and didn't know it so this is useful