Bash-like scripting has become ubiquitous in operating systems, and it makes me wonder about its widespread adoption despite lacking certain programming conveniences found in other languages. While it may not be the ideal choice for large-scale software development, the bash shell possesses unique features that make it well-suited for interactive command-line processing, including pipelining, text manipulation, and file handling. Why isn't there an alternative that combines the best of bash's command-line capabilities with the robustness and scalability of traditional programming languages. Why do even new operating systems, such as Redox OS, opt for a similar syntax rather than a completely different programming language?
Here are some of the limitations I find in Bash compared to other programming languages:
-
Syntax and Expressiveness:
- Bash has a relatively simple syntax compared to other programming languages. It lacks some advanced language features such as object-oriented programming, complex data structures, and advanced control flow constructs.
- The syntax of Bash can be less intuitive and more error-prone, especially for complex tasks or larger projects.
-
Performance:
- Bash scripts can be slower compared to compiled languages like C or Java. This is because Bash is an interpreted language, and each line of code is interpreted at runtime.
- Bash may not be the best choice for computationally intensive tasks or applications that require high performance.
-
Error Handling and Debugging:
- Error handling and debugging in Bash can be challenging. Bash does not provide robust error handling mechanisms, and error messages can be cryptic and difficult to interpret.
- Debugging Bash scripts can be cumbersome, as there is limited tooling and debugging support compared to other programming languages.
-
Portability:
- While Bash is available on most Unix-like systems, it may not be available on all platforms or versions. This can limit the portability of Bash scripts.
- Bash scripts may not work as expected on non-Unix systems or require modifications to run on different platforms.
-
Limited Standard Library:
- Bash has a limited standard library compared to other programming languages. It lacks comprehensive libraries for tasks such as networking, database access, or advanced data manipulation.
- Bash often relies on external tools or utilities to perform complex operations, which can introduce dependencies and compatibility issues.
-
Lack of Modularity and Reusability:
- Bash scripts can become monolithic and difficult to maintain as they grow in size. Bash does not provide strong mechanisms for modularization or code reuse.
- Reusing code or creating libraries in Bash can be challenging, leading to code duplication and decreased maintainability.
Bash is fine. Now powershell, that's utter garbage.
I never used Powershell. Why is it garbage in your opinion?
As someone who has used PowerShell, I can say it's amazing. Especially being a .NET developer, a lot of my knowledge transfers very well to PS. It has a ton of great built in modules and is being actively developed and improved. It also comes with an ISE which is really helpful for developing scripts.
I find that many people that don't like PS either have only used the old version that comes pre-installed on Windows - v5 which is behind the latest Core v7 - or they're bash/Linux purists
.
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 .
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.
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.
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 a lot nicer now if i want to do anything shell related.