• wwb4itcgas@lemm.eedeleted by creator
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 years ago

    I have a confession to make: Unless shell script is absolutely required, I just use Python for all my automation needs.

    • CrazyLikeGollum@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      Or scripts for basically any other variant of the Bourne shell. They are, for the most part, very cross compatible.

      • BeigeAgenda@lemmy.ca
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        I wrote a script to do backups on a ESXi it uses Busybox’s ASH, one thing I learned after spending hours debugging my scripts was that ASH does not support arrays so you have to do everything with temporary files.

        • YouAreLiterallyAnNPC@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 years ago

          There actually is an array in any POSIX shell. You get one array per file/function. It just feels bad to use it. You can abuse ‘set – 1 2 3 4’ to act as a proper array. You can then use ‘for’ without ‘in’ to iterate over it.

          for i; do echo $i; done.

          Use shift <number> to pop items off.

          If I really have to use something more complex, I’ll reach for mkfifo instead so I can guarantee the data can only be consumed once without manipulating entries.

      • Tinidril@midwest.social
        link
        fedilink
        English
        arrow-up
        0
        ·
        2 years ago

        That’s the only reason I’ve ever done much of anything in shell script. As a network administrator I’ve worked many network appliances running on some flavor of Unix and the one language I can count on to be always available is bash. It has been well worth knowing for just that reason.

  • perishthethought@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 years ago

    I don’t normally say this, but the AI tools I’ve used to help me write bash were pretty much spot on.

    • SpaceNoodle@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 years ago

      Yeah, an LLM can quickly parrot some basic boilerplate that’s showed up in its training data a hundred times.

    • marduk@lemmy.sdf.org
      link
      fedilink
      arrow-up
      0
      ·
      2 years ago

      Yes, with respect to the grey bearded uncles and aunties; as someone who never “learned” bash, in 2025 I’m letting a LLM do the bashing for me.

    • henfredemars@infosec.pub
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      For building a quick template that I can tweak to my needs, it works really well. I just don’t find it to be an intuitive scripting language.

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      Everything is text! And different programs output in different styles. And certain programs can only read certain styles. And certain programs can only convert from some into others. And don’t get me started on IFS.

  • brokenlcd@feddit.it
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    Knowing that there is still a bash script i wrote around 5 years ago still running the entirety of my high scool lab makes me sorry for the poor bastard that will need to fix those hieroglyphs as soon as some package breaks the script. I hate that i used bash, but it was the easiest option at the time on that desolate server.

    • formulaBonk@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      Bash scripts survive because often times they are the easiest option on an abandoned server

  • Aceticon@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 years ago

    When I was finishing of my degree at Uni I actually spent a couple of months as an auxiliary teacher giving professional training in Unix, which included teaching people shell script.

    Nowadays (granted, almost 3 decades later), I remember almost nothing of shell scripting, even though I’ve stayed on the Technical Career Track doing mostly Programming since.

    So that joke is very much me irl.

  • Victor@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    Ever since I switched to Fish Shell, I’ve had no issues remembering anything. Ported my entire catalogue of custom scripts over to fish and everything became much cleaner. More legible, and less code to accomplish the same things. Easier argument parsing, control structures, everything. Much less error prone IMO.

    Highly recommend it. It’s obviously not POSIX or anything, but I find that the cost of installing fish on every machine I own is lower than maintaining POSIX-compliant scripts.

    Enjoy your scripting!

    • alt_xa_23@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 years ago

      I switched to fish a while back, but haven’t learned how to script in it yet. Sounds like I should learn

    • raldone01@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 years ago

      I love fish but sadly it has no proper equivalent of set -e as far as I know.

      || return; in every line is not a solution.

    • LeninOnAPrayer@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      I wish I could but since I use bash at work (often on embedded systems so no custom scripts or anything that isn’t source code) I just don’t want to go back and forth between the two.

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        A shell script can be much more agile, potent, and concise, depending on the use case.

        E.g. if you want to make a facade (wrapper) around a program, that’s much cleaner in $SHELL. All you’re doing is checking which keyword/command the user wanted, and then executing the commands associated with what you want to achieve, like maybe displaying a notification and updating a global environment variable or something.

        Executing a bunch of commands and chaining their output together in python is surely much more cumbersome than just typing them out next to each other separated by a pipe character. It’s higher-level. 👍

        If it’s just text in text out though, sure, mostly equivalent, but for me this is rarely the use case for a script.

        • I’m not anti bash or fish, I’ve written in both just this week, but if we’re talking about readability/syntax as this post is about, and you want an alternative to bash, I’d say python is a more natural alternative. Fish syntax is still fairly ugly compared to most programming languages in my opinion.

          Different strokes for different folks I suppose.

    • _stranger_@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      2 years ago

      It’s more like bash did it one way and everyone who came after decided that was terrible and should be done a different way (for good reason).

      Looking right at you -eq and your weird ass syntax

      if [[ $x -eq $y ]]