• 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.

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

    • UndercoverUlrikHD@programming.dev
      link
      fedilink
      arrow-up
      10
      ·
      7 days 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@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        6 days 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.

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

          • Victor@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            6 days ago

            Fish syntax is still fairly ugly compared to most programming languages in my opinion.

            subprocess.run(["fd", "-t", "d", "some_query"])
            

            vs

            fd -t d some_query
            

            Which is cleaner? Not to mention if you want to take the output from the command and pipe it into another one.

            It’s not about folks with weird opinions or otherwise, it’s about use cases. 🙂 I don’t think python is any more “natural” than most other imperative languages.

            Fish is probably even more natural, actually, due to it being more high level and the legibility of the script is basically dependent on the naming of the commands and options and variables used within it, rather than something else, just like python. They probably have similarly legible keywords. Fish I imagine has fewer, which is a good thing for legibility. A script does a lot more with a lot less, due to the commands themselves doing so much behind the scenes. There’s a lot more boilerplate to a “proper” programming language than a scripting language.

            But if you want to do something that python is better suited for, like advanced data processing or number crunching, or writing a whole application, then I would say that would be the better choice. It’s not about preference for me when it comes to python vs fish, it’s about the right tool for the job. But if we’re talking about bash vs fish, then I’m picking fish purely by preference. 👍

    • raldone01@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      6 days ago

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

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

    • LeninOnAPrayer@lemm.ee
      link
      fedilink
      English
      arrow-up
      2
      ·
      6 days 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
        1
        ·
        6 days 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.

    • alt_xa_23@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      7 days ago

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

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        6 days ago

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

  • JTskulk@lemmy.world
    link
    fedilink
    English
    arrow-up
    15
    ·
    6 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

    • cm0002@lemmy.worldOP
      link
      fedilink
      arrow-up
      5
      ·
      7 days ago

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

  • DaChrissy@lemm.ee
    link
    fedilink
    English
    arrow-up
    12
    ·
    7 days 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
      arrow-up
      6
      ·
      7 days 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

        • cm0002@lemmy.worldOP
          link
          fedilink
          arrow-up
          6
          ·
          7 days 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

      • DaChrissy@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        7 days 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

  • 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.

  • Aceticon@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    8
    ·
    7 days 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.

    • _stranger_@lemmy.world
      link
      fedilink
      arrow-up
      23
      ·
      7 days 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 ]]

  • LeninOnAPrayer@lemm.ee
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    6 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
      ·
      6 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
        ·
        6 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.