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 errorsset -u
: treat references to undefined variables as errorsset -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 forcesseq
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.
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…
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.
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?
What about embedded work? You gonna run a full graphical GUI on a network router?
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?$time = (get-date).adddays(-30) gci -file -filter *.pdf ` | ? { $_.lastwritetime -gt $time } ` | % { convert -density 300 $_.fullname $($_.fullname + ".jpg") }
🤷
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?
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.
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?
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 ¯\_(ツ)_/¯
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”.
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.