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.
[ Parent
| on HN ]
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!