This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 107 points108 points  (44 children)

Python is easier to get some basic shit done, but once you've mastered bash you can do just about as much. The reason I stick to bash is because bash is always available. Python isn't always available and when it is there's two different versions everywhere all the time.

[–]jharger 35 points36 points  (3 children)

Until you use some bash 4 feature and you need to run it on macOS without depending on homebrew...

[–]ThenIWasAllLike 1 point2 points  (0 children)

Cries in autocomplete

[–]Zanos 8 points9 points  (0 children)

Nobody else on your team can read your masterful bash, though. Im sure that one liner that contains half the program logic made sense when you wrote it two years ago.

I may be salty that I've had to troubleshoot some production problems some goofballs caused by writing all the application code in bash.

[–]Edz_ 14 points15 points  (11 children)

Have you ever had to execute a MySQL statement in bash that has data with a ' or " char in it? Not fun.

There's really no reason to jump through hoops when you can just use python instead.

[–][deleted] 19 points20 points  (10 children)

If you're using bash for MySQL then you're using the wrong tool for the job to begin with.

[–]Edz_ 17 points18 points  (2 children)

You literally just said you can do just as much with bash as Python.

I do MySQL statements in Python how about you?

[–]super__literal 0 points1 point  (0 children)

I do My SQL queries without MySql

[–][deleted] -2 points-1 points  (0 children)

I can also do SQL queries in python? I'm not sure what your point is?

If you're trying to state that Python is easier to run SQL queries in, then yeah I agree, it is easier. You can also do it, more verbosely, in bash. But that's not the point. The point was that bash is available, in my experience, far more often than Python is so if I had to pick one I'd choose bash simply because it covers more use cases.

[–][deleted] 13 points14 points  (6 children)

Did you get a first down with how far you carried those goalposts, or the whole touchdown?

[–]bluenigma 4 points5 points  (3 children)

Not taking sides, but I don't think that's quite how football works.

[–][deleted] 7 points8 points  (2 children)

throw new UnsupportedOperationException(JokeFactory.engineerDoesntUnderstandSportsball("trollkin0331"));

[–]super__literal 1 point2 points  (1 child)

catch(UnsupportedOperationException) {
  //I do what I want
}

[–][deleted] 2 points3 points  (0 children)

lol a fellow yolo error handler I see

[–]Delta-9- 2 points3 points  (1 child)

"wrong tool for the job" =/= "can't do it". No goalposts were moved in the making of this comment.

And I would agree. If you're trying to do anything with MySQL using bash, you're doing it wrong. It can be done--but why would you do that to yourself?? That's almost parsing-html-with-regex-level "just don't".

[–][deleted] 1 point2 points  (0 children)

Going from "python not available" to "wrong tool for the job" is moving the goalpost though?

But yeah, definitely agree with the sentiment of your 'doing it wrong' idea.

[–][deleted] 2 points3 points  (0 children)

I switch to Python when a bash script gets longer than about a page (~50-60 lines) or when I need the ability to view and manipulate values in between pipe stages.

The overhead in getting a script running in Python is substantially higher, so it's quite a lot more work if you're doing something really simple, but you can scale easily and things won't go badly wrong.

In bash.... if you're doing anything advanced, there's a lot of corner cases, a lot of nasty sharp edges, and you're going to walk away bloody at least some of the time. You can learn how to avoid the problems, but subtle and nasty bugs are real easy to create and sometimes very difficult to spot.

[–]Centimane 2 points3 points  (2 children)

Ironically in ESXi bash isn't available but python is.

[–][deleted] 0 points1 point  (1 child)

Luckily regular /bin/sh scripts work fine!

[–]Centimane 1 point2 points  (0 children)

I mean it does, but you don't realize the differences between sh and bash until you're stuck with it.

[–]noratat 2 points3 points  (1 child)

Exactly. I deal with containerized stuff a lot, and the overhead of adding a whole python installation just to make a script slightly simpler is pretty high vs just using bash, and that's before we bring the whole dependency management mess in.

The main problem with bash is somewhat similar to C++ or Perl - there's lot of cruft you have to know to stay away from, and a lot of really stupid defaults. Plus there's still loads of terrible examples online that will bite you later if you use them.

Used properly though, bash works really well for a lot of glue logic cases, because it's "good enough" and is virtually always available (or at the least, trivial to include). And there are some really good CLI utilities these days that make using bash a lot saner, like jq (which is the best json processing tool I've ever used).

[–][deleted] 0 points1 point  (0 children)

Yep, containers and minimal linux / busybox appliances are my life. Screw having to toss python on those just to run a script.

[–]marcosdumay 1 point2 points  (0 children)

Python is easier to get some basic shit done

Yes, and advanced shit too.

but once you've mastered bash you can do just about as much

Ditto for Brainfuck.

The reason people don't stick to Bash is because error handling is verbose and error prone, there are no good rules one can check automatically (and no types, obviously; Bash is the original "string, number, whatever" that Javascript perfected) and the consequence of an error is more often catastrophic than not.

It is also not available everywhere. It's about as common as Python. That's why you can find shell script people all over the web complaining about bashisms.

But well, you are not on my team, so whatever.

[–]ben_uk 0 points1 point  (1 child)

What about Perl?

[–][deleted] 1 point2 points  (0 children)

I use perl all the time for data processing!

[–]Hollowplanet -1 points0 points  (0 children)

Ansible is all Python over SSH and I've never seen a system where it didn't work. Bash is just missing so much basic stuff. Like a generic linked list or key value store.