r/programming • u/refp • Aug 08 '26
A shell exclamation mark is not for yelling. Be lazy. | Filip Roséen
https://refp.se/articles/your-shell-and-the-lazy-exclamation-mark
152
Upvotes
r/programming • u/refp • Aug 08 '26
48
u/baked_doge Aug 08 '26
Great article, shells are so festure-full it take a very long time to become a real expert in them, even if you spend time to master them.
In a way it feels like a bit of a design failure. All the default utilities are just as feature full yet hard to master: sed can do a lot but most documentation sucks.
53
u/EnUnLugarDeLaMancha Aug 08 '26
I will never use this trick. The idea of aliasing
!to a past command that I think I remember, but I might actually be misremembering, is really scary.rm -rf /-style mistake waiting to happen. I can't see the advantage of it over a simpleCtrl+r(which, yes, it's mentioned below in the FAQ), which lets me see what I'm going to execute.The event designators are even worse. Blindly rewriting random commands, with the clarity of Bash syntax. Nope nope nope.
These are the kind of features that make people want to rewrite Bash scripts into something that is actually manageable.
2
u/Mutericator Aug 08 '26
One addendum: I'm not sure if it's every terminal emulator, but
fccan also be activated (or rather,$EDITORcan) with the Ctrl-X, Ctrl-E shortcut.Regardless: love the article and the explanation of the event/word/modifier breakdown. Definitely putting
!$:hin my toolbelt!2
u/TheBrokenRail-Dev Aug 08 '26
While this might work for interactive shells, I would never do this for scripts. And in my opinion, anything complex should always be put in a script.
Selecting arguments by index just seems like a bad idea. Adding an argument would break everything. I would much rather create a function that would then be responsible for both
mkdirandcd.4
u/__konrad Aug 08 '26
I hate that after the "event not found" error the recent command is not added to history
4
u/badmonkey0001 Aug 08 '26
2
u/wannaliveonmars Aug 08 '26
I knew about
!!, but didn't know about!ssh, that's a neat trick.3
u/sasik520 Aug 08 '26
I would never accept it in any script other than a one-timer.
But for the daily quick-n-dirty tasks, this is extremely useful. Extremely.
3
u/Glad_Position3592 Aug 08 '26 edited Aug 08 '26
Does anyone else get annoyed of the 2010 tech douche “nerd” writing style? “haha we’re programmers so we’re clearly lazy because we use shortcuts to optimize for proficiency”. Like stfu people in this industry work themselves to death and the world is exponentially worse off for it. The tech industry isn’t some nerdy niche anymore
0
u/oljimmypickles Aug 09 '26
I won't remember any of these. Additionally, utilizing key shortcuts and tab-autocomplete is still faster than typing a lot of these.
As far as
sudogoes, stop it and start usingrun0.0
u/[deleted] Aug 08 '26
[deleted] — view deleted comment