Live data from Hacker News

Bashing the Bash – Replacing Shell Scripts with Python (2017)

medium.com

31–40 of 138 posts

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#31

I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only. This really just reads like someone who doesn't know shell and does know python, but thinks the problem is the tool. They continually describe shell with phrases like "obscure and difficult-to-predict" while talking through things that are either obvious…

I agree with your sentiment. People like to complain about tools. The nice things about bash (and even sh) are that you can combine a bunch of simple tools together quickly because the syntax doesn't get in the way of it. The language designers didn't intend for people to be writing thousands of lines of scripts; they intended them to be using them locally and focused on interactivity. So naturally the syntax is nice for interactive work. It's a stretch to pretend that working with python paths is easier than working with shell paths, just like it's a stretch to say your bash machine learning library is better than a python one. The author should let things excel at what they're good at and stop pretending everything needs to be unified.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#32

I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only. This really just reads like someone who doesn't know shell and does know python, but thinks the problem is the tool. They continually describe shell with phrases like "obscure and difficult-to-predict" while talking through things that are either obvious…

> I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only.

I've only kicked the tires on both, but plumbum:

https://plumbum.readthedocs.io/en/latest/

and sh: https://amoffat.github.io/sh/

both feel pretty good in that regard.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#33
post #5

Beware of Python devs writing Python shell scripts. They're used to using all the brand new (backwards incompatible) language features as soon as they come out. The vast majority have no consideration for a 10 year old PC running a 10 year old OS. The python3.x they write will not run. Bash, surprisingly, gets backwards incompatible language features too. But the vast majority of bash developers are writing for all c…

> The vast majority have no consideration for a 10 year old PC running a 10 year old OS. The python3.x they write will not run. Python3 is just under 14 years old.

Yeah, but nobody's targeting Python 3.0; I think the point was that the Python crowd is likely to exclusively target current versions and lean on 3.6 and under being officially EOL.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#34
having a hard time being sold here.

mkdir -p would create the directory without error. checking if a directory exists is trivial before creating it. Python throws an error if the path given to os.mkdir exists too.

This article is way too long to digest, so i should stop now.

Perhaps the argument should be, rewrite hacky things in bash as programs and build them into your apps?

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#35
post #5

Beware of Python devs writing Python shell scripts. They're used to using all the brand new (backwards incompatible) language features as soon as they come out. The vast majority have no consideration for a 10 year old PC running a 10 year old OS. The python3.x they write will not run. Bash, surprisingly, gets backwards incompatible language features too. But the vast majority of bash developers are writing for all c…

> The vast majority have no consideration for a 10 year old PC running a 10 year old OS. The python3.x they write will not run. Python3 is just under 14 years old.

If you are running a 10-year old version of python 3, and you try and install some recently written python 3 application, it will never work - you'll be stuck in dependency hell, even getting pip to run may be a challenge due to outdated certs or TLS versions.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#36
I have some bad news for you, from a long, long, long time CS/EE/Sysadmin person:

I can probably run my bash script on every linux I ever touched.

I can probably have that python code break on half of the linux boxen I use. This one does not have module X installed. This one is too old, this one is too new, this python is not holding its mouth just at the right angle to work.

Yeah, bash bash all you want. I have pulled out scripts decades old and run them. I can not say the same for other things I have written.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#38

I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only. This really just reads like someone who doesn't know shell and does know python, but thinks the problem is the tool. They continually describe shell with phrases like "obscure and difficult-to-predict" while talking through things that are either obvious…

> I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only. I've only kicked the tires on both, but plumbum: https://plumbum.readthedocs.io/en/latest/ and sh: https://amoffat.github.io/sh/ both feel pretty good in that regard.

Even if you have a great library that abstracts away shell like things, you’d still probably be better served with a shell script. Shell scripts aren’t supposed to be big. They are quick one offs that solve immediate problems. This means that they are also spread around the filesystem. I’m of the opinion that one shouldn’t install libraries into the system Python path. I also tend to make heavy use of virtual envs. Setting up a venv for each off scripts doesn’t seem like a great plan.

For more centralized workflows, I could see Python shell replacements being helpful. Especially project specific scripts where the overhead of managing a venv is negligible.

But realistically replacing the majority of bash scripts? I just don’t see it.

Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)

#39

I was hoping someone finally had a library or something to make python good at the things shell does well (mostly, running stuff and piping output around). If only. This really just reads like someone who doesn't know shell and does know python, but thinks the problem is the tool. They continually describe shell with phrases like "obscure and difficult-to-predict" while talking through things that are either obvious…

After going over it again, I think I can be more precise: What annoys me is that it's inconsistent to the point of being disingenuous. Like... You want to say error handling is hard to do right? That's fine, it is. You wanna write "Checking the status of programs using $? can be accidentally left off, leading to inconsistent behavior" and then in the same article write in explicit exception handlers, and act like somehow those can't be forgotten!? Get lost.
Post reply on HN