3 ms·
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-lin
by Terr_ 2mo ago
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?
- magarnicle 2mo agoman bash. That's the secret. man bash.
- zoky 2mo agoThe 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.
- wild_egg 2mo agoDo you need to pipe the ruby output to bash? Ruby could just run the mv directly by wrapping in backticks instead of quotes.
- zoky 2mo agoRunning 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.
- inigyou 2mo agols | 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!
- rascul 2mo agoIf 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.
- pcblues 2mo agoSeems to be the flavour of the day :)
- CoastalCoder 2mo agoMaybe 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.
- refp 2mo agoI 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 https://refp.se/articles/non-constant-constant-expressions and related post in that series.