• wwb4itcgas@lemm.ee
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 day ago

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

  • JTskulk@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    4 days ago

    Bash was the first language I learned, got pretty decent at it. Now what happens is I think of a tiny script I need to write, I start writing it in Bash, I have to do string manipulation, I say fuck this shit and rewrite in Python lol

  • conditional_soup@lemm.ee
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    5 days ago

    Regex

    Edit: to everyone who responded, I use regex infrequently enough that the knowledge never really crystalizes. By the time I need it for this one thing again, I haven’t touched it in like a year.

    • 9point6@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      5 days ago

      You get used to it, I don’t even see the code—I just see: group… pattern… read-ahead…

    • Kissaki@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      arrow-down
      1
      ·
      5 days ago

      You always forget regex syntax?

      I’ve always found it simple to understand and remember. Even over many years and decades, I’ve never had issues reading or writing simple regex syntax (excluding the flags and shorthands) even after long regex breaks.

      • Akito@lemmy.zip
        link
        fedilink
        English
        arrow-up
        0
        ·
        5 days ago

        It’s not about the syntax itself, it’s about which syntax to use. There are different ones and remembering which one is for which language is tough.

        • Lehmanator@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 days ago

          This is exactly it. Regex is super simple. The difficulty is maintaining a mental mapping between language/util <-> regex engine <-> engine syntax & character class names. It gets worse when utils also conditionally enable extended syntaxes with flags or options.

          The hardest part is remembering whether you need to use \w or [:alnum:].

          Way too few utils actually mention which syntax they use too. Most just say something accepts a “regular expression”, which is totally ambiguous.

    • kameecoding@lemmy.world
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      5 days ago

      Most of regex is pretty basic and easy to learn, it’s the look ahead and look behind that are the killers imo

    • HyperMegaNet@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      4 days ago

      Thank you for this. About a year ago I came across ShellCheck thanks to a comment just like this on Reddit. I also happened to be getting towards the end of a project which included hundreds of lines of shell scripts across dozens of files.

      It turns out that despite my workplace having done quite a bit of shell scripting for previous projects, no one had heard about Shell Check. We had been using similar analysis tools for other languages but nothing for shell scripts. As you say, it turned up a huge number of errors, including some pretty spicy ones when we first started using it. It was genuinely surprising to see how many unique and terrible ways the scripts could have failed.

  • Victor@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    5 days 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!

  • umbraroze@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    5 days 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.

  • Pixelbeard@lemmy.ca
    link
    fedilink
    Français
    arrow-up
    1
    ·
    4 days 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
        arrow-up
        2
        ·
        2 days 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
          arrow-up
          1
          ·
          2 days ago

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

    • CrazyLikeGollum@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      5 days ago

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

      • Tinidril@midwest.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        5 days 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.

  • 6mementomorib@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    4 days ago

    i used powershell, and even after trying every other shell and as a die hard Linux user I’ve considered going back to powershell cause damn man

    • ronflex@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      4 days ago

      I am a huge fan of using PowerShell for scripting on Linux. I use it a ton on Windows already and it allows me to write damn near cross-platform scripts with no extra effort. I still usually use a Bash or Fish shell but for scripting I love being able to utilize powershell.

  • perishthethought@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    5 days ago

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