Explanation for newbies:

  • Shell is the programming language that you use when you open a terminal on linux or mac os. Well, actually “shell” is a family of languages with many different implementations (bash, dash, ash, zsh, ksh, fish, …)

  • Writing programs in shell (called “shell scripts”) is a harrowing experience because the language is optimized for interactive use at a terminal, not writing extensive applications

  • The two lines in the meme change the shell’s behavior to be slightly less headache-inducing for the programmer:

    • set -euo pipefail is the short form of the following three commands:
      • set -e: exit on the first command that fails, rather than plowing through ignoring all errors
      • set -u: treat references to undefined variables as errors
      • set -o pipefail: If a command piped into another command fails, treat that as an error
    • export LC_ALL=C tells other programs to not do weird things depending on locale. For example, it forces seq to output numbers with a period as the decimal separator, even on systems where coma is the default decimal separator (russian, dutch, etc.).
  • The title text references “posix”, which is a document that standardizes, among other things, what features a shell must have. Posix does not require a shell to implement pipefail, so if you want your script to run on as many different platforms as possible, then you cannot use that feature.

  • blaue_Fledermaus@mstdn.io
    link
    fedilink
    arrow-up
    7
    arrow-down
    14
    ·
    11 hours ago

    I’m glad powershell is cross-platform nowadays. It’s a bit saner.

    Better would be to leave the 1970s and never interact with a terminal again…

    • tiramichu@lemm.ee
      link
      fedilink
      arrow-up
      12
      ·
      edit-2
      11 hours ago

      What else are you going to do, though?

      If you have some particular and complicated task then sure you’d probably write a program for it in a specific high-level language. But that isn’t what the shell is for.

      If you’ve already got a bunch of apps and utilities and want to orchestrate them together to do a task, that’s a good shell use case.

      Or if you have a system that needs setup and install tasks doing on it to prepare for running your actual workload, that’s also a task which the shell is ideally suited to.

      Shell scripting always has a place, and I can’t see it being made obsolete any time soon.

      • renzev@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        5
        ·
        11 hours ago

        People keep on telling me that python is a “scripting language” but honestly I would rather use the shoddiest and most barebones shell you would give me than python if I had to make a script. It all boils to interfaces, and there are more programs, libraries, and daemons that have a shell interface as opposed to whatever other “better” language there is out there. Trying to write scripts with Python or ruby or whatever will just boils down to plumbing data between external programs in a less succinct syntax. What good is type safety, try/catch, and classes if all the tools that you’re using are taking in and spitting out raw text anyway?

    • lambalicious@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      8 hours ago

      Quick, how do I do for i in $(find . -iname '*.pdf' -mtime -30); do convert -density 300 ${i} ${i}.jpeg; done in a GUI, again?

      • bradd@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        3 hours ago
        $time = (get-date).adddays(-30)
        gci -file -filter *.pdf `
          | ? { $_.lastwritetime -gt $time } `
          | % { convert -density 300 $_.fullname $($_.fullname + ".jpg") }
        

        🤷

    • ccunning@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      11 hours ago

      I’m a former (long long ago) Linux admin and a current heavy (but not really deep) powershell user.

      The .net-ification of *nix just seems bonkers to me.

      Does it really work that well?

      • renzev@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        3
        ·
        8 hours ago

        The .net-ification of *nix just seems bonkers to me.

        It IS bonkers. As a case study, compare the process of setting up a self-hosted runner in gitlab vs github.

        Gitlab does everything The Linux Way. You spin up a slim docker container based on Alpine, pass it the API key, and you’re done. Nice and simple.

        Github, being owned by Microsoft, does everything The Microsoft way. The documentation mentions nothing of containers, you’re just meant to run the runner natively, essentially giving Microsoft and anyone else in the repo a reverse shell into your machine. Lovely. Microsoft then somehow managed to make their runner software (reminder: whose entire job consists of pulling a git repo, parsing a yaml file, and running some shell commands) depend on fucking dotnet and a bunch of other bullshit. You’re meant to install it using a shitty setup.sh script that does that stupid thing with detecting what distro you’re on and calling the native package manager to install dependencies. Which of course doesn’t work for shit for anyone who’s not on debain or fedora because those are the only distro’s they’ve bothered with. So you’re either stuck setting up dotnet on your system, or trying to manually banish this unholy abomination into a docker container, which is gonna end up twice the size of gitlab’s pre-made Alpine container thanks to needing glibc to run dotnet (and also full gnu coreutils for some fucking reason)

        Bloat is just microsoft’s way of doing things. They see unused resources, and they want to use them. Keep microsoft out of linux.

      • nesc@lemmy.cafe
        link
        fedilink
        English
        arrow-up
        6
        ·
        10 hours ago

        What type of .net-ification occurs on *nix? I am current linux “admin” and there is close to 0 times where I’ve seen powershell not on windows. Maybe in some microsoft specific hell-scape it is more common, but it’s hard to imagine that there are people that can accept a “shell” that takes 5-10 seconds to start. There are apps written in c# but they aren’t all that common?

        • ccunning@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          10 hours ago

          I honestly don’t know but there must some translation happening between .net objects and *nix.

          And .net “core” started supporting Linux like a decade ago. I’m guessing they’re related ¯\_(ツ)_/¯

      • blaue_Fledermaus@mstdn.io
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        11 hours ago

        I usually only use the terminal when I don’t find an alternative, but powershell usually feels a bit saner than bash.

        I’ve also tried nushell, also nice, but in a few situations powershell despite usually being verbose was more “elegant”.

    • renzev@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      7
      arrow-down
      1
      ·
      11 hours ago

      Better would be to leave the 1970s and never interact with a terminal again…

      I’m still waiting for someone to come up with a better alternative. And once someone does come up with something better, it will be another few decades of waiting for it to catch on. Terminal emulation is dumb and weird, but there’s just no better solution that’s also compatible with existing software. Just look at any IDE as an example: visual studio, code blocks, whatever. Thousands of hours put into making all those fancy buttons menus and GUIs, and still the only feature that is worth using is the built-in terminal emulator which you can use to run a real text editor like vim or emacs.