Bashing the Bash – Replacing Shell Scripts with Python (2017)
1–10 of 138 posts
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#2Previous discussion: https://news.ycombinator.com/item?id=14998213
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#3> 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? There needs to be more reason than this.
> The revised code is easier to read and maintain, runs a little faster, and can have a proper unit test suite.
Three claims. Any data to support it?
Some of the examples of "bash is bad" are also not convincing to me. Here's an example:
> An example of a shell obscurity is the way the current working directory is set. The cd command is clear enough, but in the presence of sub-shells using (), can make it difficult to discern a stack of nested shell invocations and how the working directory changes when the sub-shells exit.
So...why do you have "a stack of nested shell invocations" that all need to be working directory aware? And how would this be any better in Python? (It could be better in either Python or Bash but either one still requires the developer to avoid simple mistakes.)
I don't know. I don't get it. I feel like the author had the unfortunate experience of knowing more Python than Bash and inheriting someone else's (who also didn't have much Bash experience) crappy Bash code.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#4(Sorry, Oingo Boingo)
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#5Bash, surprisingly, gets backwards incompatible language features too. But the vast majority of bash developers are writing for all computers, not just computers with software from the last 3 years.
Python language could work if you stuck to an old target. But python culture is a problem and makes this very unlikely. What python is, and what python devs deal with, changes constantly. That doesn't work for shell scripts where stability is king.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#6This 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 it's theoretically possible to write _any_ program in bash that can be written in Python. It might be a hell of a lot uglier and lack things like imports, modules, etc., but it can be done.
For example, there is an implementation of an HTTP daemon written purely in bash[2]. Once again-- terrible idea, but great execution.
[1]: https://en.wikibooks.org/wiki/Bash_Shell_Scripting#A_few_not...
[2]: https://github.com/avleen/bashttpd
edit: added newline to separate references
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#7(2017) Previous discussion: https://news.ycombinator.com/item?id=14998213
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#8This 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 with experience or from context, and then write something different in python (i.e. something you could write in BASH that does something different) that's not less obscure but is only using python obscurity.
> An example of a shell obscurity is the way the current working directory is set. The cd command is clear enough, but in the presence of sub-shells using (), can make it difficult to discern a stack of nested shell invocations and how the working directory changes when the sub-shells exit.
Er... yeah? So you expect PWD to be a global and it was actually a local?
Or more explicitly:
> One of the shell’s ickier features is that variables tend to be global. There are some exceptions and caveats, however, that lead to shell scripts that are broken or behave inconsistently.
That's not a shell feature, that's just how people frequently write it - you can make functions and declare your variables local if you want. I can easily write a python script with all my variables at the top, too.
Re: Bashing the Bash – Replacing Shell Scripts with Python (2017)
#9I wouldn’t want to worry about python environment when dealing with OS post-install scripting for instance.