Live data from Hacker News

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

medium.com

11–20 of 138 posts

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

#11

I think this article is supposed to commend Python as a better choice than Bash? I think the author forgot to make a convincing argument for that, though. > The point of bash-bashing is to reduce use of the shell. That's a tautology. I get it, we're supposed to reduce the use of bash ... but why? > Without much real work, it’s easy to replace shell scripts with Python code. But you're writing the same thing again? Th…

bash is anti-bicycle: no matter how long you use, it trips you up. https://www.oilshell.org/why.html

Shell is great for one liners to run commands, cancerous for anything more complex. Fabric combines the best of both worlds: shell for one liners, Python for more complex logic https://docs.fabfile.org/en/2.6/getting-started.html#addendu...

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

#12
post #11

I think this article is supposed to commend Python as a better choice than Bash? I think the author forgot to make a convincing argument for that, though. > The point of bash-bashing is to reduce use of the shell. That's a tautology. I get it, we're supposed to reduce the use of bash ... but why? > Without much real work, it’s easy to replace shell scripts with Python code. But you're writing the same thing again? Th…

bash is anti-bicycle: no matter how long you use, it trips you up. https://www.oilshell.org/why.html Shell is great for one liners to run commands, cancerous for anything more complex. Fabric combines the best of both worlds: shell for one liners, Python for more complex logic https://docs.fabfile.org/en/2.6/getting-started.html#addendu...

In my experience, it trips me up no more than Python or Fabric do. I have used Fabric a lot too. At another job, we built all of our pipeline tooling in it.

I somehow keep returning to Bash, though. I enjoy it.

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

#13
post #11

I think this article is supposed to commend Python as a better choice than Bash? I think the author forgot to make a convincing argument for that, though. > The point of bash-bashing is to reduce use of the shell. That's a tautology. I get it, we're supposed to reduce the use of bash ... but why? > Without much real work, it’s easy to replace shell scripts with Python code. But you're writing the same thing again? Th…

bash is anti-bicycle: no matter how long you use, it trips you up. https://www.oilshell.org/why.html Shell is great for one liners to run commands, cancerous for anything more complex. Fabric combines the best of both worlds: shell for one liners, Python for more complex logic https://docs.fabfile.org/en/2.6/getting-started.html#addendu...

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?

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

#14
post #11

Earlier quoted context omitted.

bash is anti-bicycle: no matter how long you use, it trips you up. https://www.oilshell.org/why.html Shell is great for one liners to run commands, cancerous for anything more complex. Fabric combines the best of both worlds: shell for one liners, Python for more complex logic https://docs.fabfile.org/en/2.6/getting-started.html#addendu...

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.

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

#15
As much as I appreciate Python, I much rather use Perl as a replacement for complex shell scripts. Perl 5 is ubiquitous, it has been stable for the best part of the last 20 years and it's unbeatable for all those tasks that involve heavy text processing.

Python is good for complex, structured applications, but shell scripts are not that. Shell scripts are glue, and there's arguably no better glue than Perl.

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

#16

As much as I appreciate Python, I much rather use Perl as a replacement for complex shell scripts. Perl 5 is ubiquitous, it has been stable for the best part of the last 20 years and it's unbeatable for all those tasks that involve heavy text processing. Python is good for complex, structured applications, but shell scripts are not that. Shell scripts are glue, and there's arguably no better glue than Perl.

I am well versed in the shell, perl and python.

I first learned the shell, and pretty much stuck to it conservatively avoiding bash extensions.

Later, I learned perl (around version 4)

my first impression of perl was annoyance.

$foo = 123;

seemed silly because there was a dollar sign on the left side of the assignment. and... $foo, @foo, $', $_, s/abc/def/;

all the syntax seemed needlessly cryptic and reinforced the "perl is a write-only language" idea in my mind.

But then something happened.

At some point all of these idioms went away as I became fluent and could think in perl.

Because there were many ways to do something in perl, I found that it become VERY easy to get an idea in my head out into working code.

So perl was to me my most expressive language.

But what I've noticed is that many people haven't overcome the syntax barrier and perl looks like line noise to them. More worrying is the fact that everyone can get their ideas into perl, but because people solve problems so differently their perl can be vastly different from what I am accustomed to.

So a few years later I learned python. The indentation requirement was a minor annoyance, but that was quickly overcome by the consistency and visual structure it added.

A more major annoyance was that many things were harder to implement in python. Regular expressions is a huge one - they are a major feature of perl and I had learned to use them liberally.

Yet I persisted and with help from the many "batteries included" with python, I was easily writing portable maintainable scripts in python.

And they were still readable after 6 months.

Now I write only small shell scripts, and past a certain size all other scripting is in python. It's quite easy to write meaningful scripts in python. (I've pretty much lost my fluency in perl via python -- I fumble around now looking at or modifying perl scripts)

by the way argparse is quite easily my favorite import in python.

  parser = argparse.ArgumentParser(argument_default=None)
  parser.add_argument('-d', '--debug',  action='store_true', help='debug flag')
  parser.add_argument('-c', '--config', default="~/.config", help='config file name')
  arg = parser.parse_args()

  if arg.debug:
    print('config file: %s'%arg.config)

  ...

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

#18
In my experience, bash makes the simple things simple and the hard things (like complex pipelines, validating arguments, or “pure bash”) really hard. YMMV.

Python makes everything medium difficulty which can be a big win depending on the size of automation required.

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

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

Post reply on HN