News for hackers. Stuff that matters.
Re:A shell exclamation mark is not for yelling. Be lazy. by hnlmorg on Wednesday August 12, 2026 @05:24AM (#49269745)
I’ve been burnt before using ! and forgetting what command I typed previously, thus invoking the wrong command line.

!! is handy for the sudo example, but beyond that, I tend to prefer pressing the up arrow to cycle through the history rather than picking the first item. Eg:

  !ssh
vs

  ssh[up]

It’s the same number of key strokes but less error prone
Re:A shell exclamation mark is not for yelling. Be lazy. by refp on Wednesday August 12, 2026 @06:07AM (#49270046)
Worth noting that `ssh[up]` isn't available by default in bash nor zsh — though it wouldn't surprise me if helpers such as oh-my-zsh enables it for you. `ssh[up]` is certainly an awesome feature — though (perhaps sadly) not default behavior.

> I've been burnt before using ! and forgetting what command I typed previously

If you want to make sure you do not execute commands you did not intend to, the section linked below is a great start:

- https://refp.se/articles/your-shell-and-the-lazy-exclamation...

You may also look into `magic-space` which makes the expansion of event-designators happen inline, I thought about including it but the article felt long even without it.

Thanks for reading the article, I hope it was a worthwhile read even with alternate workflows elsewhere!

Re:A shell exclamation mark is not for yelling. Be lazy. by hnlmorg on Wednesday August 12, 2026 @06:41AM (#49270313)
Thanks for the tips. These days I don’t use sh derivatives as my primary shell and the shell I do use has a few features to make command search more ergonomic and safer. But these are useful tips nonetheless
Re:A shell exclamation mark is not for yelling. Be lazy. by CoastalCoder on Wednesday August 12, 2026 @05:38AM (#49269832)
Agreed. I especially cringed at the author's example of mixing that with "sudo".
Re:A shell exclamation mark is not for yelling. Be lazy. by pcblues on Wednesday August 12, 2026 @07:12AM (#49270610)
That's mixing human memory with root access. Worse than AI :) I have lost more to mistakes than bugs over 30 years.
Re:A shell exclamation mark is not for yelling. Be lazy. by refp on Wednesday August 12, 2026 @05:42AM (#49269860)
the "mixing of sudo"-example is using `!!`, which as explained is the immediately previous command, a little confused how that translates to the "execute command somewhere in the history" argument?
Re:A shell exclamation mark is not for yelling. Be lazy. by CoastalCoder on Wednesday August 12, 2026 @06:34AM (#49270272)
I suppose it depends on the kinds of mistakes to which one is prone.
Re:A shell exclamation mark is not for yelling. Be lazy. by pwdisswordfishq on Wednesday August 12, 2026 @06:07AM (#49270049)

    bind space:magic-space
Re:A shell exclamation mark is not for yelling. Be lazy. by mkl on Wednesday August 12, 2026 @08:38AM (#49271454)
Or alt-^ to do it without any configuration.