• @PieMePlenty
    link
    23 hours ago

    My google history hits for powershell for loop is is in the dozens.

  • @JTskulk
    link
    English
    44 hours 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

  • @[email protected]
    link
    fedilink
    English
    2
    edit-2
    5 hours 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”.

    • @[email protected]
      link
      fedilink
      54 hours 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.

      • @[email protected]
        link
        fedilink
        English
        13 hours 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.

  • @LovableSidekick
    link
    English
    4
    edit-2
    7 hours ago

    The older you get, the more things are like programming in bash.

  • @[email protected]
    link
    fedilink
    English
    68 hours 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.

  • @[email protected]
    link
    fedilink
    810 hours 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
      link
      38 hours 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.

  • @baratheon
    link
    English
    812 hours ago

    to be honest I agree and thought we would be using something more intuitive by now

    • JackbyDev
      link
      fedilink
      English
      59 hours 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.

  • Victor
    link
    2917 hours 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!

    • @[email protected]
      link
      fedilink
      English
      25 hours 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
        link
        13 hours ago

        Yeah, using one tool and then another one can be confusing at times. 😅

    • @[email protected]
      link
      fedilink
      911 hours ago

      If you’re going to write scripts that requires installing software, might as well use something like python though? Most Linux distros ship also ship with python installed

      • Victor
        link
        3
        edit-2
        4 hours 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.

        • @[email protected]
          link
          fedilink
          12 hours ago

          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.

    • @raldone01
      link
      611 hours 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.

    • JackbyDev
      link
      fedilink
      English
      29 hours ago

      It’s the default on CachyOS and I’ve been enjoying it. I typically use zsh.

      • Victor
        link
        14 hours ago

        Yeah I also went bash -> zsh -> fish. Zsh was just too complicated to configure for my taste. Couldn’t do it, apart from copy pasting stuff I didn’t understand myself, and that just didn’t sit right.

      • Victor
        link
        13 hours ago

        Happy adventuring! ✨

    • alt_xa_23
      link
      19 hours ago

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

      • Victor
        link
        14 hours ago

        Give it a shot after reading through the manual! (Extremely short compared to bash’s!) It’s a joy in my opinion. ☺️👌

    • @[email protected]
      link
      fedilink
      712 hours 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.

    • @[email protected]
      link
      fedilink
      English
      519 hours 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.

      • Trailblazing Braille Taser
        link
        fedilink
        717 hours ago

        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.

        • @[email protected]
          link
          fedilink
          49 hours 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
        link
        317 hours 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”?

  • @[email protected]
    link
    fedilink
    Français
    210 hours 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é!

    • @[email protected]
      link
      fedilink
      English
      310 hours 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.

    • @cm0002OP
      link
      517 hours ago

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

  • katy ✨
    link
    fedilink
    2320 hours ago

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

  • @[email protected]
    link
    fedilink
    English
    717 hours 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.