News for hackers. Stuff that matters.
Re:Shell Script Best Practices, from a decade of scripting t... by ilyt on Thursday October 27, 2022 @08:55AM (#33356766)
> Hands down, shell scripting is one of my all time favorite languages. It gets tons of hate, e.g. "If you have to write more than 10 lines, then use a real language," but I feel like those assertions are more socially-founded opinions than technically-backed arguments.

It is "opinion" based on debugging scripts made by people (which might be "you but few years ago") that don't know the full extent of death-traps that are put in the language. Or really writing anything more complex.

About only strong side of shell as a language is a pipe character. Everything else is less convenient at best, actively dangerous at worst.

Sure, "how to write something in a limited language" might be fun mental excercise but as someone sitting in ops space for good part of 15 years, it's just a burden.

Hell, I'd rather debug Perl script than Bash one...

Yeah, if it is few pipes and some minor post processing I'd use it too (pipe is the easiest way to do it out of all languages I've seen) but that's about it.

It is nice to write one-liners in cmdline but characteristic that make it nice there make it worse programming language. A bit like Perl in that matter

Re:Shell Script Best Practices, from a decade of scripting t... by sophacles on Thursday October 27, 2022 @06:06PM (#33364678)
You say this as if it wasn't extremely common to find giant python monstrosities that can be replaced by a handful of lines of shell. TBF the shell code often is not just cleaner and easier to follow, but also faster.

It's possible to use the wrong tool for the job in any language - including language choice itself.

Dismissing a programming language because it's not shell and dismissing shell because it's not a proramming language are the same thing - a bad idea if that's your only decision criteria.

Re:Shell Script Best Practices, from a decade of scripting t... by GoblinSlayer on Friday October 28, 2022 @07:08AM (#33369876)
Bash is a good tool if the script is short enough, but if you have to write more than 10 lines, then use a real language.
Re:Shell Script Best Practices, from a decade of scripting t... by sophacles on Friday October 28, 2022 @12:06PM (#33373279)
Nonsense. That's a terrible metric.

If i need to run 11 commands in a row, suddenly i need to make sure new tooling is installed in my instance and/or ship a binary?

What if that 11 lines is setting up some networking? Now i need to go write a 400 line go program to use netlink to accomplish the same task? Or should I condense that to 80 lines of go to shell out the commands that replicate the 11 lines of simple bash?

There are plenty of reasons to do this, I have done it more than once. None of those reasons are "crossed an arbitrary magic number of 'lines of shell'".

Re:Shell Script Best Practices, from a decade of scripting t... by sshd on Friday October 28, 2022 @07:43PM (#33379423)
If my bash script is more than 10 lines, I switch to python and if that's more than 10 lines I switch to C! And if that's more than 10 lines I use assembly!

/s