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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  • nous@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    POSIX compliance for the most part. Which is meant to give you a consistent API you can write software against that will work on any UNIX system. At least that is the theory behind it. It basically acts as a lowest common denominator for UNIX systems. Want to write a script that will work on all systems - bash or a similar shell will almost certainly be present.

    A new system can change this if they wanted to. But then they won’t be able to take advantage of all the existing bash scripts out there that everyone is writing. Which adds a lot of friction to adoption.

    So in a way we are locked into a bash like shell now. Unless you can get a lot of distros to change this shell it is very hard to change it for a single one. And changing something so fundamental across lots of distros will upset a lot of people that are used to bash.

    And shells overall are preferred to general purpose programming languages as their main focus is executing other commands and piping input/output from one to another or to/from files. Something most programming languages make a bit awkward as that is not their focus.

    There are a bunch of non-POSIX shells, like fish, nushell, ion etc but these will likely not become the default anytime soon due to the inertia that bash has. But luckjly you can install what ever shell or language you want in addition to bash and switch to that for your interactive shell or even scripting if you want to. They just won’t become the defaults for a long time - if ever.

  • matthewmercury@reddthat.com
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Bash isn’t the only shell. Most systems can use zsh or fish or tcsh or whatever shell you prefer, if you like that better than bash. You’re gonna have to run a shell if you want to use the terminal, though, you understand that?

    Shell scripts are very good for specific tasks. Don’t use them for tasks that are unsuitable. Use python or go or node or c if those are better for your needs. Use the right tool for the job. But also, learn to understand why the industry has been using shell scripts for decades.

  • QuazarOmega@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Everyone talks about the fact that Bash is what it is because it is first and foremost an interactive shell, but nowadays some design decisions are just inexcusable in my opinion, like the awful syntax of common programming constructs, the if in particular, that would only benefit from following how every other language works even if they aren’t meant as shells.
    Some also argue against the non-modularity with the fact that you should use it for only quick and easy stuff, but that’s just an excuse, if the language runtime that comes preinstalled in your system had modern features and sane syntax you would stick to that and save yourself from installing Python/Ruby if they’re not needed; and it is clear that there is a need for modularity, otherwise plugin managers wouldn’t exist, many swear by downloading the scripts directly and sourcing them in the name of “KISS”, but that is just silly when there is a good system set in place that makes it actually easier to manage it all.
    Then there’s the issue of the holy pipelining, that has more or less been overcome by some languages already, this example in Rust shows that it can be easy, so there’s no reason why a terse scripting language couldn’t achieve the same.

    In the end I don’t know what’s holding the landscape back, I noticed Xonsh that looks very interesting, but I never tried it, I wonder if it is POSIX compliant and if that aspect even is so fundamental to the success of a shell

  • nyan@lemmy.cafe
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Let’s see here. We’re talking about a thirty-plus-year-old language that was deliberately written as a superset of sh from 1979. Its main purpose is to glue together other command-line programs on 'NIXish systems to automate complex procedures for sysadmins. Using it as a general-purpose programming language, while not impossible, is kinda dumb if you have any other options. Within its original niche, it ain’t broke, so there’s no need to fix it.

    It’s a contemporary of Tcl and Perl, not of Python and Java (and sh is from the era where microcomputers mostly used BASIC dialects). Unlike Perl, it didn’t bolt on object orientation or other more modern features afterwards—and really, Perl was intended as just the kind of “shell script killer” you seem to be thinking of in your introduction. However, it never completely displaced the shell built-in scripting languages even in the days before it fell out of favour itself. Might be that there’s a reason for that.

  • bionicjoey@lemmy.ca
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Bash adheres to the POSIX standard for a shell, which limits what it can have in terms of UX. If you really want something with a different UX you can try something like fish. Just be warned that if you do, you’ll quickly learn how wrong your bullet point about bash not being portable is.

  • h3ndrik@feddit.de
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    why are you stuck with bash? just write a shebang and then your interpreter in the first line of your script.

    i can use bash, python, lua and al kinds of stuff…

    i don’t understand the question. if you mean, why does my shell only accept bash syntax, if i set my shell to bash, idk. use another shell?

    ‘sh’ is kind of the smallest common thing that’s available everywhere. so when you got to script something that needs to run somewhere not under your control, you use ‘sh’. and that’s kind of it works. you’ll find something, that’s been around for some time, otherwise it won’t have spread everywhere. and now you can’t replace it in newer products, because there is so much stuff using it.

    if that isn’t one of your problems, go with my first suggestions and just use python or something like that as your scripting language.

  • Crunkle_Foreskin@kbin.social
    cake
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    1 year ago

    I wouldn’t use the word “stuck”, Bash is a result of over 50 years of technological advancement and experience. It works on servers, remotely, is lean and powerful. It’s not that user friendly, because it doesn’t need to be.

    ZSH and Fish are available on *nix systems for a little bit more sugar. I personally don’t use raw Bash because I just love what ZSH can do, but I love writing Bash scripts.

    • GodOfThunder@lemm.eeOP
      link
      fedilink
      arrow-up
      19
      ·
      1 year ago

      This is so cool. It’s exactly what I had in mind when thinking of a modern bash alternative.

  • 𝘋𝘪𝘳𝘬@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    What features does bash have that make it so suitable for shells?

    You mean, except being automatically available in basically every Linux distribution without having to install any additional software?

    • HeavyRust@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      They’re asking why it became available everywhere.

      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.

      • ffhein@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Because other languages available at that time lacked certain programming conveniences found in bash :) Despite its shortcomings, it’s still a very convenient language for running other programs, working with files, and piping output from one program to another, or to a file. Bash was first released in 1989, and I don’t know exactly when it passed the threshold for widespread adoption, but I can’t think of anything that would’ve been a better alternative.

        I think OP is also asking “why aren’t people switching to something else now” which is a completely different question.