Live data from Hacker News

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

medium.com

111–120 of 138 posts

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

#111

I'm fully in favor of replacing shell scripts with Python3 scripts wherever possible. In fact that's part of my job. That being said, the author of this article is using confusing / wrong terminology to discuss bash. This article says that, "The [bash] shell isn't a complete programming language". While I agree that bash lacks any real data types besides strings, bash is a Turing-complete programming language[1], so…

> For example, there is an implementation of an HTTP daemon written purely in bash[2]. Once again-- terrible idea, but great execution.

It's not pure bash, as it relies on netcat or socat plus some other external programs (ls, tree, cat, date).

There does exist a pure bash httpd though. It relies on a loadable builtin (from the bash tree though not built by default).

https://github.com/dzove855/Bash-web-server

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

#112

Earlier quoted context omitted.

That's what Python2.7 is and why every major proprietary product won't adopt anything else. It's also why it won't go away. All of my Python 2.6-2.7 scripts haven't been touched in 10 years in production and they aren't likely to ever be updated. I actually now refuse to write new Python that isn't compatible with both 2&3 for this reason. Python3 refuses to stabilize.

I’ve been slowly embracing the mantra “only use unmaintained software”: maintenance is great when it’s fixing bugs and such, but eventually people insist on breaking backwards compatibility.

That is a captivating idea!

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

#113

Earlier quoted context omitted.

That's what Python2.7 is and why every major proprietary product won't adopt anything else. It's also why it won't go away. All of my Python 2.6-2.7 scripts haven't been touched in 10 years in production and they aren't likely to ever be updated. I actually now refuse to write new Python that isn't compatible with both 2&3 for this reason. Python3 refuses to stabilize.

> It's also why it won't go away. Python 2 went away in macOS. Bash still exists.

https://www.python.org/downloads/release/python-2718/

There's still a macOS installer for the latest release of Python2.7 (4/20/2020).

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

#114

Earlier quoted context omitted.

That's what Python2.7 is and why every major proprietary product won't adopt anything else. It's also why it won't go away. All of my Python 2.6-2.7 scripts haven't been touched in 10 years in production and they aren't likely to ever be updated. I actually now refuse to write new Python that isn't compatible with both 2&3 for this reason. Python3 refuses to stabilize.

I’ve been slowly embracing the mantra “only use unmaintained software”: maintenance is great when it’s fixing bugs and such, but eventually people insist on breaking backwards compatibility.

Python2.7 is still maintained.

If you mean my software I mentioned if something breaks I'm still required to fix it. I just doubt that will happen at this point and have other tasks to do.

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

#115
post #60

Earlier quoted context omitted.

Over the past decade I've been drifting towards doing more and more in bash that I'd've normally done one one language or another just because of this stability. Perl is another candidate if I need something more complicated, but I'm not as familiar with it so I don't really reach for it often. Are there any other languages with the same stability that would also fill this niche?

For shell-scripting sorts of tasks, there’s also awk which I find a nice sort of halfway between bash and Perl. Also, I’ve been using various lisps (elisp in emacs org-mode and Common Lisp) and they both can be written in ways that will probably last a long time.

Awk is a strange seeming suggestion, but I agree it's probably the next most universal, installed, stable over time option, and more readable than sh.

Using awk as a general purpose language means slightly bending it out of shape, by mostly ignoring the main section (which runs once per selected record of input) and writing your entire program in a big END{} section.

BUT

* It's installed everywhere and has been forever just like sh

* A 20 year old awk script from hpux or something, works in todays gawk, just like sh.

* Unlike sh, the language is more like a normal generic language than, making it more readable and less arcane for non-trivial jobs.

For example, bash has a handy substitute feature, in the form of a brace expansion. ${FOO//a/b}

Awk has an actual sub() or gsub() function.

A lot of things in bash require tricks essentially abusing various fancy brace expansions and messing with IFS to hijack the line parser into doing things there is no explicit command for, especially if you're avoiding external commands. IE you're not simply writing code that does what it says, you're running a bash interpreter in your head and manipulating strings so that when they are expanded and resolved, they mean something to the the parser and results in the parser doing something more useful. It's like your always writing code that writes code, instead of just writing code.

External dependencies is another whole point too. Shells main explicit job is to run other programs. You actually have to work pretty hard not to run an external binary by accident, ie you have know which commands are built in and which are executables. In awk or anything else, you have to go out of your way to exec() or system().

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

#116

Earlier quoted context omitted.

I’ve been slowly embracing the mantra “only use unmaintained software”: maintenance is great when it’s fixing bugs and such, but eventually people insist on breaking backwards compatibility.

Python2.7 is still maintained. If you mean my software I mentioned if something breaks I'm still required to fix it. I just doubt that will happen at this point and have other tasks to do.

Isn’t Python 2.7 EOL as of January 2020 or something? It’s maintained in the sense that there are still people shipping patches, but the core Python developers no longer maintain it.

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

#117
post #20

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. xonsh ( https://xon.sh/ ) Been using it for a few years now. It's worth it.

I haven't heard of xonsh either till now. After looking it over, it seems like a perfect integration of sh with Python. There's a good chance I'll give an honest shot at migrating from zsh to xonsh this week.

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

#118

Earlier quoted context omitted.

We had some problem, roughly, "run a tool on all YAML files in the directory" or something. The first attempt that led to a production outage: (It is late, bash examples are approximate. Don't sweat the syntax.) the_tool *.yaml There weren't any YAML files, so argv[1] was literally "*.yaml", which then wasn't found, leading to errors, etc. shopt -s nullglob the_tool *.yaml (Don't even get me started on how there's sh…

find . -maxdepth 1 -name '*.yaml' -print0 | xargs -r0 the_tool >To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. If you have a problem that involves "run a command with a list of parameters but not if the list is empty" and you don't immediately think of `xargs -r`, then…

Doesn’t xargs also die at too many files? Fact is, bash manages to have more footguns than goddamn C, which is telling something

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

#119

Earlier quoted context omitted.

We had some problem, roughly, "run a tool on all YAML files in the directory" or something. The first attempt that led to a production outage: (It is late, bash examples are approximate. Don't sweat the syntax.) the_tool *.yaml There weren't any YAML files, so argv[1] was literally "*.yaml", which then wasn't found, leading to errors, etc. shopt -s nullglob the_tool *.yaml (Don't even get me started on how there's sh…

> To say "you're holding it wrong" is just folly. Bash is worthy of the same treatment that "A Fractal of Bad Design" gave PHP, and it has no place in anything that wants to call itself engineering. is this a cloud AMD64 opinion that ignores the 2 trillion devices which Gartner predicts will never run python? I recently finished a ~600 lines ash script and the kids at work which just graduated complained that *"Y u n…

How is bash performant? It is literally interpret by lines, and starting a whole process per if statements..

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

#120

Earlier quoted context omitted.

Interesting, I used fabric many years ago but thought it had been deprecated. However, it still seems remote focused. Is that a problem for a shell replacement?

As far as I understand, Invoke is pretty much local Fabric. Or rather, Fabric is a networking layer on top of Invoke.

Thanks, looks like it has some similarities with make, however doesn't skip things already built.
Post reply on HN