• @traches@sh.itjust.works
        link
        fedilink
        English
        2
        edit-2
        2 months ago

        I’d been considering it for awhile, but thought it wasn’t worth the trouble of switching until I realized just how often I do things the tedious manual way because writing a bash script to do it is so arcane

  • Rose
    link
    fedilink
    292 months ago

    There’s always the old piece of wisdom from the Unix jungle: “If you write a complex shellscript, sooner or later you’ll wish you wrote it in a real programming language.”

    I wrote a huge PowerShell script over the past few years. I was like “Ooh, guess this is a resume item if anyone asks me if I know PowerShell.” …around the beginning of the year I rewrote the bloody thing in Python and I have zero regrets. It’s no longer a Big Mush of Stuff That Does a Thing. It’s got object orientation now. Design patterns. Things in independent units. Shit like that.

    • @cm0002@lemmy.worldOP
      link
      fedilink
      52 months ago

      For a defacto windows admin my Powershell skills are…embarrassing lol but I’m getting there!

  • 74 183.84
    link
    fedilink
    English
    122 months ago

    And I thought I was the only one… for smaller bash scripts chatGPT/Deepseek does a good enough job at it. Though I still haven’t tried VScode’s copilot on bash scripts. I have only tried it wirh C code and it kiiiinda did an ass job at helping…

    • @cm0002@lemmy.worldOP
      link
      fedilink
      62 months ago

      AI does decently enough on scripting languages if you spell it out enough for it lol, but IMO it tends to not do so well when it comes to compiled languages

      I’ve tried Python with VScode Copilot (Claude) and it did pretty good

      • 74 183.84
        link
        fedilink
        English
        12 months ago

        Yeah I tried that, Claude with some C code. Unfortunately the Ai only took me from point A to point A. And it only took a few hours :D

        • @cm0002@lemmy.worldOP
          link
          fedilink
          62 months ago

          I was chalking it up to some scripting languages just tending to be more popular (like python) and thus having more training data for them to draw from

          But that’s a good point too lol

    • JackbyDev
      link
      fedilink
      English
      62 months 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.

  • @KazuchijouNo@lemy.lol
    link
    fedilink
    252 months ago

    Today I tried to write bash (I think)

    I grabbed a bunch of commands, slapped a bunch of “&&” to string them together and saved them to a .sh file.

    It didn’t work as expected and I did not, at all, look at any documentation during the process. (This is obviously on me, I’ll try harder next time)

    • @DeRp_DaWg@lemmy.world
      link
      fedilink
      72 months ago

      I try to remember to use man when learning a new command/program. And I almost always half-ass it and press the search button immediately to find whatever flag i need.

  • @Pixelbeard@lemmy.ca
    link
    fedilink
    Français
    32 months ago

    Je comprend tellement! Je répond en français pour ma première réponse sur Lemmy juste pour voir comment ça va être géré!

      • @Pixelbeard@lemmy.ca
        link
        fedilink
        21 month ago

        En un mundo ideal. Todo se traduciría automáticamente del idioma original al idioma del lector y viceversa

        • @admin@sh.itjust.works
          link
          fedilink
          11 month ago

          ¿No nos volvería lentos y flojonazos? (not a real word if you translate, more like slang meaning to be really lazy)

    • @Pixelbeard@lemmy.ca
      link
      fedilink
      English
      32 months ago

      I so understand! Answering I. French for my first Lemmy reply just to see how it’s handled.

      Realizing now that language selection is mainly for people filtering. It be cool if it auto translated for people that need it.

  • katy ✨
    link
    fedilink
    262 months ago

    every control structure should end in the backwards spelling of how they started

  • @jaybone@lemmy.world
    link
    fedilink
    22 months ago

    Or it’s because other people are assholes. And write shit garbage. And then you go to fix a bug or add an enhancement. And then you are stuck.

  • @Gobbel2000@programming.dev
    link
    fedilink
    122 months ago

    So true. Every time I have to look up how to write a bash for loop. Where does the semicolon go? Where is the newline? Is it terminated with done? Or with end? The worst part with bash is that when you do it wrong, most of the time there is no error but something completely wrong happens.

    • @ClemaX@lemm.ee
      link
      fedilink
      13
      edit-2
      2 months ago

      It all makes sense when you think about the way it will be parsed. I prefer to use newlines instead of semicolons to show the blocks more clearly.

      for file in *.txt
      do
          cat "$file"
      done
      

      The do and done serve as the loop block delimiters. Such as { and } in many other languages. The shell parser couldn’t know where stuff starts/ends.

      Edit: I agree that the then/fi, do/done case/esac are very inconsistent.

      Also to fail early and raise errors on uninitialized variables, I recommend to add this to the beginning of your bash scripts:

      set -euo pipefail
      

      Or only this for regular sh scripts:

      set -eu
      

      -e: Exit on error

      -u: Error on access to undefined variable

      -o pipefail: Abort pipeline early if any part of it fails.

      There is also -x that can be very useful for debugging as it shows a trace of every command and result as it is executed.

    • @qjkxbmwvz@startrek.website
      link
      fedilink
      2
      edit-2
      2 months ago

      I can only remember this because I initially didn’t learn about xargs — so any time I need to loop over something I tend to use for var in $(cmd) instead of cmd | xargs. It’s more verbose but somewhat more flexible IMHO.

      So I run loops a lot on the command line, not just in shell scripts.