So, you don’t know Python at all AND you don’t know Bash, but you feel compelled to talk about how one is so much better than the other?
I have plenty of experience with Bash, hence why I was eager to question the implication that bash was less complicated than other solutions.
You’re correct that I don’t know python, but I do have plenty of familiarity with PHP, JS, C#, and Rust. From my experience with those languages I guessed that python probably has similar libraries for making API calls.
Thanks for providing the actual examples. Looking at them I’m curious if you still think I’m wrong?
In my opinion the bash is much more difficult to understand than the python and therefore it’s more likely for bugs to creep in. For example I think curl_exit_code=$? should be called immediately after the curl command as the way it’s presently written isn’t it capturing the exit code of the tail command?
You’ve explicitly called --connect-timeout and --max-time. imo it only comes from experience that you need to add these options. I had a script that had been funcitoning without issue for months then suddenly started to hang and it was a while before I figured out that the defaults for curl had no timeout so it didn’t gracefully fail like I would expect.
These are the kind of traps that I fall into all the time with bash and it’s painful to debug.
have plenty of experience with Bash, hence why I was eager to question the implication that bash was less complicated than other solutions.
You said “Scripting in bash is an indescribably painful experience.”
That’s an opinion, and it’s certainly yours to have. In my experience, neither of those solutions to the problem you suggested are all that complicated.
In my opinion the bash is much more difficult to understand than the python and therefore it’s more likely for bugs to creep in.
You could say this about any language/script, it’s all about our individual experiences.
That’s a great catch on the $?, sadly, I just handed you copypasta i glanced at them to make sure they looked decent before posting. If you swap it around it appears to run fine. You’ll also need to install / use jq to do the proper json parsing.
imo it only comes from experience that you need to add these options
it’s optional in the python too. You can also use the OS builtin “timeout” when calling a command to generically kill it off if it doesn’t exit in a timeframe.
Sure, I’ve done some scary things in bash before. Some of them went to production. :) timeout tail -f > output to grab x seconds of a log for monitoring.
IMHO, Bash is fine (and rapid) up to a point. It’s available on all flavors of Linux/Unix, with some minor attention to Posix, you can make it run efficiently on most anything (except maybe fish, had a couple of devs that REALLY swore by fish, but it wasn’t nice about syntax.)
Bash is more available without privilege and more backward compatible. It does lack finess and utility for larger projects. At some point, you need to do things that are better managed in Python libraries.
I would not want to attempt a proper web server CGI in bash, nor try heavy math.
Bash is nice because you’re using OS binaries behind the scenes to do the heavy lifting. They’re all written in something optimized and beefy. It’s like you get to use all the power and stability of C projects with the duct tape speed and efficiency that surpasses most of the scripting languages. It’s a hell of a lot easier to do system calls in bash than py :)
I have plenty of experience with Bash, hence why I was eager to question the implication that bash was less complicated than other solutions.
You’re correct that I don’t know python, but I do have plenty of familiarity with PHP, JS, C#, and Rust. From my experience with those languages I guessed that python probably has similar libraries for making API calls.
Thanks for providing the actual examples. Looking at them I’m curious if you still think I’m wrong?
In my opinion the bash is much more difficult to understand than the python and therefore it’s more likely for bugs to creep in. For example I think
curl_exit_code=$?
should be called immediately after the curl command as the way it’s presently written isn’t it capturing the exit code of the tail command?You’ve explicitly called
--connect-timeout
and--max-time
. imo it only comes from experience that you need to add these options. I had a script that had been funcitoning without issue for months then suddenly started to hang and it was a while before I figured out that the defaults forcurl
had no timeout so it didn’t gracefully fail like I would expect.These are the kind of traps that I fall into all the time with bash and it’s painful to debug.
response=$( curl \ --silent \ --write-out "\n%{http_code}" \ --connect-timeout "$CONNECT_TIMEOUT" \ --max-time "$MAX_TIME" \ "$API_URL" ) http_body=$(echo "$response" | sed '$d') http_code=$(echo "$response" | tail -n1) curl_exit_code=$?
You said “Scripting in bash is an indescribably painful experience.”
That’s an opinion, and it’s certainly yours to have. In my experience, neither of those solutions to the problem you suggested are all that complicated.
You could say this about any language/script, it’s all about our individual experiences.
That’s a great catch on the $?, sadly, I just handed you copypasta i glanced at them to make sure they looked decent before posting. If you swap it around it appears to run fine. You’ll also need to install / use jq to do the proper json parsing.
it’s optional in the python too. You can also use the OS builtin “timeout” when calling a command to generically kill it off if it doesn’t exit in a timeframe.
Sure, I’ve done some scary things in bash before. Some of them went to production. :) timeout tail -f > output to grab x seconds of a log for monitoring.
IMHO, Bash is fine (and rapid) up to a point. It’s available on all flavors of Linux/Unix, with some minor attention to Posix, you can make it run efficiently on most anything (except maybe fish, had a couple of devs that REALLY swore by fish, but it wasn’t nice about syntax.)
Bash is more available without privilege and more backward compatible. It does lack finess and utility for larger projects. At some point, you need to do things that are better managed in Python libraries.
I would not want to attempt a proper web server CGI in bash, nor try heavy math.
Bash is nice because you’re using OS binaries behind the scenes to do the heavy lifting. They’re all written in something optimized and beefy. It’s like you get to use all the power and stability of C projects with the duct tape speed and efficiency that surpasses most of the scripting languages. It’s a hell of a lot easier to do system calls in bash than py :)