• wwb4itcgas@lemm.ee
    link
    fedilink
    English
    arrow-up
    2
    ·
    3 days 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
    15
    ·
    7 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

  • 6mementomorib@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    9
    ·
    7 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
      5
      ·
      7 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.

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      6
      ·
      7 days 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.

  • jkercher@programming.dev
    link
    fedilink
    English
    arrow-up
    7
    ·
    7 days ago

    Meh. I had a bash job for 6 years. I couldn’t forget it if I wanted to. I imagine most people don’t use it enough for it to stick. You get good enough at it, and there’s no need to reach for python.

  • LeninOnAPrayer@lemm.ee
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    7 days ago

    The sad thing is that even chatgpt can’t program in bash. I just want a simple script and every single time it just doesn’t work. I always just end up saying “write this in python instead”.

    • Hawk@lemmynsfw.com
      link
      fedilink
      arrow-up
      6
      ·
      7 days ago

      Python’s usually the better choice anyway tbf. I know piping isn’t as good, but there are so many footguns!

      Nushell and Fish can be really convenient too.

      I used to adhere to sh for an OpenBSD machine but I switched to python, Rust and Go for, even simple things.

      • sunstoned@lemmus.org
        link
        fedilink
        English
        arrow-up
        2
        ·
        7 days ago

        Python is just as portable these days (on modern hardware, caveats, caveats).

        Honestly so intuitive that I start there too unless I have a need for speed or distinct memory control. There’s no job too small for a python script.

  • Pixelbeard@lemmy.ca
    link
    fedilink
    Français
    arrow-up
    3
    ·
    7 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
      English
      arrow-up
      3
      ·
      7 days 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.

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

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

  • conditional_soup@lemm.ee
    link
    fedilink
    arrow-up
    121
    arrow-down
    9
    ·
    edit-2
    7 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.

    • LeninOnAPrayer@lemm.ee
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      7 days ago

      I just use the regex101 site. I don’t need anything too complicated ever. Has all the common syntax and shows matches as you type. Supports the different languages and globals.

    • dirtycrow@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      7 days ago

      For me I spent one hour of ADHD hyper focusing to get the gist of regex. Python.org has good documentation. It’s been like 2 years so I’ve forgotten it too lol.

    • 9point6@lemmy.world
      link
      fedilink
      arrow-up
      40
      ·
      7 days ago

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

    • kameecoding@lemmy.world
      link
      fedilink
      arrow-up
      34
      arrow-down
      2
      ·
      7 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

    • Kissaki@programming.dev
      link
      fedilink
      English
      arrow-up
      14
      arrow-down
      2
      ·
      7 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
        15
        ·
        7 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
          3
          ·
          6 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.

        • Lehmanator@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 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.

        • Lehmanator@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 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.

        • Lehmanator@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 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.

          • ewenak@jlai.lu
            link
            fedilink
            arrow-up
            1
            arrow-down
            1
            ·
            7 days ago

            There is the “very magic” mode for vim regexes. It’s not the exact PCRE syntax, but it’s pretty close. You only need to add \v before the expression to use it. There is no permanent mode / option though. (I think you can remap the commands, like / to /\v)

        • activ8r@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          2
          ·
          6 days ago

          I know that LLMs are probably very helpful for people who are just getting started, but you will never understand it if you can’t grasp the fundamentals. Don’t let “AI” make you lazy. If you do use LLMs make sure you understand the output it’s giving you enough to replicate it yourself.

          This may not be applicable to you specifically, but I think this is nice info to have here for others.

          • TheEighthDoctor@lemmy.zip
            link
            fedilink
            English
            arrow-up
            1
            ·
            6 days ago

            I have no interest in learning regex ever in my life, I have better things to dedicate my brain capacity to haha

    • HyperMegaNet@lemm.ee
      link
      fedilink
      arrow-up
      8
      ·
      7 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.

    • ethancedwards8@programming.dev
      link
      fedilink
      English
      arrow-up
      6
      ·
      7 days ago

      I wish it had a more comprehensive auto correct feature. I maintain a huge bash repository and have tried to use it, and it common makes mistakes. None of us maintainers have time to rewrite the scripts to match standards.

      • I honestly think autocorrecting your scripts would do more harm than good. ShellCheck tells you about potential issues, but It’s up to you to determine the correct behavior.

        For example, how could it know whether cat $foo should be cat "$foo", or whether the script actually relies on word splitting? It’s possible that $foo intentionally contains multiple paths.

        Maybe there are autofixable errors I’m not thinking of.

        FYI, it’s possible to gradually adopt ShellCheck by setting --severity=error and working your way down to warnings and so on. Alternatively, you can add one-off #shellcheck ignore SC1234 comments before offending lines to silence warnings.

        • UndercoverUlrikHD@programming.dev
          link
          fedilink
          arrow-up
          4
          ·
          7 days ago

          For example, how could it know whether cat $foo should be cat "$foo", or whether the script actually relies on word splitting? It’s possible that $foo intentionally contains multiple paths.

          Last time I used ShellCheck (yesterday funnily enough) I had written ports+=($(get_elixir_ports)) to split the input since get_elixir_ports returns a string of space separated ports. It worked exactly as intended, but ShellCheck still recommended to make the splitting explicit rather than implicit.

          The ShellCheck docs recommended

          IFS=" " read -r -a elixir_ports <<< "(get_elixir_ports)"
          ports+=("${elixir_ports[@]}")
          
      • stetech@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        7 days ago

        Then you’ll have to find the time later when this leads to bugs. If you write against bash while declaring it POSIX shell, but then a random system’s sh doesn’t implement a certain thing, you’ll be SOL. Or what exactly do you mean by “match standards”?

    • CrazyLikeGollum@lemmy.world
      link
      fedilink
      English
      arrow-up
      17
      ·
      8 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
        11
        ·
        8 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.

      • BeigeAgenda@lemmy.ca
        link
        fedilink
        arrow-up
        2
        ·
        7 days 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
          4
          ·
          7 days 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.

  • perishthethought@lemm.ee
    link
    fedilink
    English
    arrow-up
    51
    arrow-down
    5
    ·
    8 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.

    • marduk@lemmy.sdf.org
      link
      fedilink
      arrow-up
      25
      arrow-down
      5
      ·
      8 days 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.

    • SpaceNoodle@lemmy.world
      link
      fedilink
      arrow-up
      17
      ·
      edit-2
      8 days ago

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

    • henfredemars@infosec.pub
      link
      fedilink
      English
      arrow-up
      6
      ·
      8 days 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.

    • ewenak@jlai.lu
      link
      fedilink
      arrow-up
      1
      ·
      7 days ago

      If When the script gets too complicated, AI could also convert it to Python.

      I tried it once at least, and it did a pretty good job, although I had to tell it to use some dedicated libraries instead of calling programs with subprocess.