Use a better programming language. Go, Typescript, Rust, Python, and even Perl come to mind.
Use a better programming language. Go, Typescript, Rust, Python, and even Perl come to mind.
I don't think LOC is the correct criterion.
I do solve many problems with bash and I enjoy the simplicity of shell coding. I even have long bash scripts. But I do agree that shell scripting is the right solution only if
= you can solve the problem quickly
= you don't need data structures
= you don't need math
= you don't need concurrencybut yea, shell is foremost a composition language/environment
Sometimes options are limited to what you know already.
You mean, the complexity of shell coding? Any operation that in a regular language is like foo.method(arg) in shell expands into something like ${foo#/&$arg#%} or `tool1 \`tool2 "${foo}"\` bar | xargs -0 baz`.
Note what you just said: when you want an object with a method that takes a parameter, you find bash too complex.
You gave an example that is not appropriate for bash.
However, bash does have functions. So if you don't need an entire underlying object system just to run your logic, you could have
function foomethod () {
parm1=$1
#more logic
}Be damned the day I decided to write a set of scripts in it rather than looking for a way to make typescript my daily driver, like it is now. Bash “code” “base” is one of the worst programming jokes.
Meanwhile, 10 year old Bash scripts I've written still run unmodified.
Winner by a mile (from a software-longevity and low-maintenance perspective at least): Bash
Compare a Python script to a Bash script. If your Python3 script (assuming no dependencies) doesn't work after 6 months I got some questions for you.
(And I don't really get how a 6 month old Python _project_ is likely to fail. I guess I'm just good at managing my dependencies?)
I know that this is probably beyond bash scripting vs python scripting but I was just replying to how 6 months project can have problems.
Also not a 6 months scale but the python standard library definitely changes and I would take bash anytime if I have to use venv for running util scripts.
Edit: When python3.8 removed 'time.clock()' it was annoying to change that. I know that it was deprecated since 3.3 (as I remember) but this is the example I have in mind now. But probably it was before I was born that people using
start=$(date +%s%N)
end=$(date +%s%N)
And I will be dead before/if this becomes impossible to use.
Bun has similar features: https://bun.sh/docs/runtime/shell