Earlier quoted context omitted.
> 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 tha…
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 prora…
Shell script best practices, from a decade of scripting things
451–460 of 500 posts
Re: Shell script best practices, from a decade of scripting things
#452Hands 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. My basic thesis is that Shell as a programming language---with it's dynamic scope, focus on line-oriented text, and pipelines---is simply a different p…
Hard Disagree. Bash programming: - no standard unit testing - how do you debug except with printlns? Fail. - each line usually takes a minimum of 10 minutes to debug unless you've done bash scripting for... ten years - basic constructs like the arg array are broken once you have special chars and spaces and want to pass those args to other commands. and UNICODE? Ha. - standard library is nil, you're dependent on a ho…
Any example with this? The following works reasonably well for me.
args=(-a --b 'arg with space' "一 二 三")
someprog "${args[@]}"Re: Shell script best practices, from a decade of scripting things
#453Hands 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. My basic thesis is that Shell as a programming language---with it's dynamic scope, focus on line-oriented text, and pipelines---is simply a different p…
There are workloads where shell scripts are the so-called right tool for a job . All too often I see people writing scripts in "proper" languages and calling os.system() on every other line. Shell scripts are good for gluing programs together. It's fine to use them for that.
Re: Shell script best practices, from a decade of scripting things
#454Earlier quoted context omitted.
POSIX shell is the standard, not bash.
That ship has sailed, because busybox ash and dash continually implement some of bash features and semantics, which come from ksh. And OSH implements almost all of bash That is, The posix shell spec is missing a lot of reality. It’s not very actively maintained, unfortunately The canonical example is not having local vars, which basically every shell supports
Re: Shell script best practices, from a decade of scripting things
#455Earlier quoted context omitted.
Awk is awesome but saying it literally takes 1 hour to properly learn it is a bit overselling.
What? The awk manual is only 827 highly technical pages[1]. If you can't read and interalize that in an hour, I suspect you're a much worse programmer than the OP. [1] https://www.gnu.org/software/gawk/manual/gawk.html For the sarcasm impared among us, everything above this, but possibly including this sentence is sarcasm.
The quick one ~ true ~ fix was ! or #! without the 1024k copyright.
s-expression notation avoids the issue with (."contents")
MS Windows interpretation is much more terse & colorful.
Re: Shell script best practices, from a decade of scripting things
#456Earlier quoted context omitted.
I noticed that I became so much more quick after taking 1 hour to properly learn awk. Yes, it literally takes about 1 hour.
The only thing I use AWK for is getting at columns from output, (possibly processing or conditionally doing something on each) what would be the next big use-case?
Scripted cholmskey grammar ( https://en.wikipedia.org/wiki/Universal_grammar ) to unleash the power of regular expressions.
Re: Shell script best practices, from a decade of scripting things
#457Earlier quoted context omitted.
Shell and SQL make you 10x productive over any alternative. Nothing even comes close. I've seen people scrambling for 1 hours to write some data munging, then spend another 1 hour to run it through a thread pool to utilize those cores , while somebody comfortable is shell writes a parallelized one liner, rips through GBs of data, and delivers the answer in 15 minutes. What Python is to Java, Shell is to Python. It sp…
For simple scripting tasks, yes. I have had the opposite experience for more critical software engineering tasks (as in, coding integrated over time and people). Language aside, the ecosystem and culture do not afford enough in way of testing, dependency management, feature flags, static analysis, legibility, and so on. The reason people say to keep shell programs short is because of these problems, it needs to be po…
Re: Shell script best practices, from a decade of scripting things
#458Earlier quoted context omitted.
"Primitive" seems like the wrong word to apply. A modern Python programmer (a common example) might think that anything not OOP is archaic. But OOP is just one design pattern. And... it can easily lead to over-engineering and delight in the pattern per se. Bash, awk, grep et alii don't do OOP. But they are close to the data and are powerful. Compaints about the notation of these tools (e.g. "line noise") are becoming…
""Primitive" seems like the wrong word to apply" Painful, ugly, unpleasant?
Code that we might deem "beautiful" may not even compile. ^_^
Does the tool do what it needs to do without getting fussy, gobbling RAM, and requiring a small army of maintainers to feed the monster? There is most definitely a place in technology for that kind of sanity.
There is something to be said for a design that doesn't bring with it a brigade of Opinions-As-A-Service proponents.
Any non-trivial notation is going to require learning. There is absolute value in learning. I think of many flexible and effective notations in tooling that has literally been the foundation of modern computing.
Maybe we are in the age of the Mono-Notation Luxury Coder. ^_^
Re: Shell script best practices, from a decade of scripting things
#459Earlier quoted context omitted.
> while somebody comfortable is shell writes a parallelized one liner Do you have an example of this? I didn’t even know you could make sql calls in scripts.
mysql, psql etc. let you issue sql from the command line I don't do much sql in bash scripts but I do keep some wrapper scripts that let me run queries from stdin to databases in my environment
Re: Shell script best practices, from a decade of scripting things
#460Earlier quoted context omitted.
> while somebody comfortable is shell writes a parallelized one liner Do you have an example of this? I didn’t even know you could make sql calls in scripts.
mysql, psql etc. let you issue sql from the command line I don't do much sql in bash scripts but I do keep some wrapper scripts that let me run queries from stdin to databases in my environment