News for hackers. Stuff that matters.
Re:A shell exclamation mark is not for yelling. Be lazy. by Terr_ on Wednesday August 12, 2026 @02:50AM (#49268685)
Rather than a sense of "cool" or "useful" somehow I end up just feeling despair at how organically convoluted it is to determine what something on a command-line really does. To be fair, I've always been biased towards "only the simplest scripts should be in shell languages."

This also adds an intriguing new dimensions to reviewing/verifying shell commands as benign and correct... How long until LLMs start (ab)using the trick in little requests they want me to approve?

Re:A shell exclamation mark is not for yelling. Be lazy. by magarnicle on Wednesday August 12, 2026 @05:26AM (#49269770)
man bash. That's the secret. man bash.
Re:A shell exclamation mark is not for yelling. Be lazy. by zoky on Wednesday August 12, 2026 @06:14AM (#49270098)
The cool thing about programming languages like Ruby is that they’re very conducive to one-liners. You can use them to generate bash statements that you can then pipe back to bash. `ls | ruby -nle 'puts "mv #{$_} #{$_.gsub(/_/, ".")}"' | bash` is a pattern I use all the time, for example. Easy way of generating complex bash statements without having to bother with the bash man page.
Re:A shell exclamation mark is not for yelling. Be lazy. by wild_egg on Wednesday August 12, 2026 @07:03AM (#49270522)
Do you need to pipe the ruby output to bash? Ruby could just run the mv directly by wrapping in backticks instead of quotes.
Re:A shell exclamation mark is not for yelling. Be lazy. by zoky on Sunday August 16, 2026 @04:02AM (#49317899)
Running it through the pipe lets you preview the command first and make sure it actually looks correct. Then you just re-run the command and append the bash pipe.
Re:A shell exclamation mark is not for yelling. Be lazy. by inigyou on Wednesday August 12, 2026 @09:37AM (#49272224)
ls | while read filename; do mv "$filename" "$(echo "$filename" | sed "s/_/./g")" || break; done

I think there's a variable expansion syntax that does replacement, but I haven't learned it so I use sed.

I find that piping to a while loop is often simpler and more flexible than something like you've written, but maybe not in this specific case with the weird string replacement syntax. However, mine doesn't have a command injection vulnerability (that I know of).

A real scripting language can also do this easily:

for f in os.listdir("."): os.rename(f, f.replace("_","."))

Sometimes I'm tempted to make Python my shell. The fewer different syntaxes you need to learn for the same basic operations, the better!

Re:A shell exclamation mark is not for yelling. Be lazy. by rascul on Wednesday August 12, 2026 @11:07AM (#49273585)
If you want to use ruby then just use ruby? That is a very fragile way to use bash that could easily lead to bad things.
Re:A shell exclamation mark is not for yelling. Be lazy. by pcblues on Wednesday August 12, 2026 @07:09AM (#49270588)
Seems to be the flavour of the day :)
Re:A shell exclamation mark is not for yelling. Be lazy. by CoastalCoder on Wednesday August 12, 2026 @05:37AM (#49269829)
Maybe it's a bit like current C++ language spec:

There's enough complexity in the language spec that most people stick with a (fairly shared) subset.

Bash can be very powerful, but IMHO there's a certain point where I find it saner to accomplish the same thing via Python.

Re:A shell exclamation mark is not for yelling. Be lazy. by refp on Wednesday August 12, 2026 @09:03AM (#49271779)
I think you are very much on point, I can definitely relate to the complexity of C++ turning it both into a wonderful adventure, but also a swamp where every step feels uncertain.

Disclaimer; author of this post, and also https://refp.se/articles/non-constant-constant-expressions and related post in that series.