Bash-like scripting in shells is prevalent in operating systems but I don’t understand why, when it doesn’t have the syntax to make programming easy like other languages. What features does bash have that make it so suitable for shells? Why even new operating systems like Redox OS choose a very similar syntax over a completely different programming language?
Bash is fine. Now powershell, that’s utter garbage.
On behalf of garbage, I loudly protest on this attempt to assimilate it to Powershell.
Bah! I find it hard to believe that if you ever truly used ps that you’d think it was garbage.
I’m rather fond of it myself.
Work forbids me from writing scripts in anything other than PowerShell or Batch and its painful. Would be a non-issue if I could use anything else. I’m all too familiar with ps and its overly long commands.
I upvoted because fuck microsoft but i was very surprised at how easy it was to script in ps. Outputs are formatted similarly and you can quite easily have exactly the info you want ,how you want, while in bash its a lot more loose. That comes with the open source territory though.
That’s about why I don’t like it. Commands are too verbose and specific.
This, powershell is pretty nice albeit verbose and TTY in Windows suck and slow (haven’t scripted in PS since 4 years ago so not sure about current state of affairs). Python is my de-facto shell now if I want to do anything shell related.
PS is still slow AF
.
50k lines is, IMHO, way too large for a bash script. I’d switch to python long before before that. Bash is primarily an *interactive shell. Bash has a lot of nice scripting capabilities (that few are aware of, let alone use) but its primary use is not as a programing language. As far as standard libraries go: sed, awk, grep, curl, netcat, etc… provide plenty of advanced capabilities. That’s the Unix philosophy, lots of small utilities that each do one thing well and that work with streams of bytes as i/o. Tie them together with a powerful shell, and an ordinary user can do quite a lot without “programming”. Is the Unix philosophy perfect? No. Has it proved to be the most flexible and successful compute environment developed for over 50 years? Yes.
Engineering is tradeoffs.
A command shell is focused on file operations and starting/stopping applications. So it makes it easy to do those things.
You can use scripting languages (e.g. Node.js/Python) to do everything bash does but they are for general purpose computing and so what and how you perform a task becomes more complicated.
This is why its important to know multiple languages, since each one will make specific tasks easier and a community forms around them as a result.
If I want to mess with the file system/configuration I will use Bash, if I want to build a website I will use Typescript, if I want to train a machine learning model I will use Python, if I am data engineering I will use Java, etc .
I personally wouldn’t, because the Unix philosophy should still apply. If you need 50k lines of bash to do something that a collection of existing command line tools already can do, you may need to re-evaluate your needs.
As @[email protected] said here, POSIX compliance is extremely important. Much of the “real world” infrastructure is still UNIX based, especially in finance. It isn’t easy to replace those systems at all, especially a legacy codebase that literally the entire world runs on. COBOL and Fortran applications in banking are still being updated today, despite efforts to modernise systems because they just work and the code is pretty much hardened at this point.
As always, in every industry, there is a “right tool” for the job. The great thing about the Unix philosophy is, if correctly applied across your stack, it doesn’t matter what language you write the tools in. Your bash script is only going to be forwarding that output to something that is suited to handle it. This person sped up their python application by using Rust for one set of functions.