News for hackers. Stuff that matters.
Re:Pure Bash Bible by jigglesniggle on Thursday September 19, 2019 @01:15AM (#21013485)
While this is interesting I see doing anything but launching programs with simple text-substituted arguments as too much for bash or sh. Run shellcheck on some of your own code, or the code of even a simple project to see how hard it is to really use bash.

Why I think people gravitate towards it is because languages such as python add too much pomp to launching a shell process. A language like perl is usually easier to use but everyone hates it now.

Re:Pure Bash Bible by dyanaraps on Thursday September 19, 2019 @02:16AM (#21013760)
The shell is my favorite language and I really don't know why.

It's definitely possible to write shell code which properly passes shellcheck's linter though it's an uphill battle to learn the ins and outs and _why_ X is wrong when Y is right.

I even managed to write a full TUI file manager in bash!

https://github.com/dylanaraps/fff

I full understand that there are times when the shell should not be used and when other languages are a better way to solve a specific problem, however I love pushing the shell beyond its supposed limits! :)

Re:Pure Bash Bible by jgtrosh on Thursday September 19, 2019 @03:35AM (#21014137)
Have you read Bash Pitfalls[1]? Do you write truly correct Bash/POSIX code? Do you still love it?

[1]: https://mywiki.wooledge.org/BashPitfalls

Re:Pure Bash Bible by dyanaraps on Thursday September 19, 2019 @03:46AM (#21014188)
> Have you read Bash Pitfalls[1]?

I've read pretty much everything I could get my hands on regarding the shell (including the mentioned link) and I still love it.

> Do you write truly correct Bash/POSIX code?

If we define correct as passing shellcheck, avoiding all pitfalls and maintaining compatibility (POSIX sh not bash), then yes, I like to think so. :)

> Do you still love it?

Oh yeah! I've been writing a ton of POSIX sh as of late. My latest project being a Linux distribution: https://getkiss.org/

(hello from Firefox in KISS!)

Re:Pure Bash Bible by jgtrosh on Thursday September 19, 2019 @06:11AM (#21014855)
Wow, very impressive. Do you also believe it's a viable language with which newcomers should start writing scripts?

Edit: follow up question is Do you believe bash / POSIX shells actually follow KISS principles?

Not questioning whether your OS is KISS, but I don't think that necessarily reflects the KISS-ness of the underlying language.

My questions clearly reflect my current impression that in the long term, shell pitfalls largely undermine the benefits of its apparent simplicity. The gist would be for you to provide some way to change my mind. I guess the codebase you provide is a strong counter example; but you'll agree it doesn't reflect general usage of shell in the wild.

Edit 2: You know what, I just read your original comment again. I kind of retract my question since you do concede that it's an uphill battle and you love it in spite of its flaws. I guess that's cool (and I agree it's fun trying to write correct bash as a challenge) as long as you're in control of the code being produced, but my main impression remains that it's a bad language to publicize and its presence in most codebases inherently bears a strong cost.

Re:Pure Bash Bible by dyanaraps on Thursday September 19, 2019 @06:35AM (#21014973)
> Do you believe bash / POSIX shells actually follow KISS principles?

POSIX `sh` yes. `bash` less so but I'd still lean more towards a yes.

Ultimately though, it depends on how we define "simple". Both `bash` (2.6MB) and POSIX `sh` shells (`dash` (232KB), `ash` (1.2MB (busybox)), etc) are tiny in size if we compare them to Python (137MB) or Perl (44MB).

(Numbers taken from my system using `du` on each file which belongs to each shell/language.)

If we define "simple" to language features then I think the shells come out on top again (especially POSIX `sh`).

If we define "simple" as ease of use (without shooting yourself in the foot) then I'd agree with you and say that the shell loses here.

There's a time and place for using any tool (in production) but I find it fun to push the shell beyond what is thought possible in my personal projects. :)

Re:Pure Bash Bible by lenkite on Thursday September 19, 2019 @08:31AM (#21015517)
Shell scripts also win "simple" in ease of deployment. (well assuming the author has paid attention to platform differences)
Re:Pure Bash Bible by wolfhumble on Thursday September 19, 2019 @05:00AM (#21014523)
From what I understand, the commenter is the author of 'Pure Bash Bible' :-) https://getkiss.org/pages/team/
Re:Pure Bash Bible by danielecook on Thursday September 19, 2019 @01:58AM (#21013683)
I don’t think it’s pomp. Once I learned Unix pipes and the tools for manipulating data (sed awk cut etc), it just became much faster and easier than writing python scripts that do the same thing. You can literally connect the output of one process to the input of another with a single character. It’s much more complex in python.

It also tends to be very portable.

Re:Pure Bash Bible by jigglesniggle on Thursday September 19, 2019 @02:13AM (#21013744)
I think you're reading my comment the wrong way: I meant to say that doing e.g. piping in Python is a lot of pointless work (pomp), as you agree.

This is perhaps one big benefit but not one that is exclusive to a sh-like language. Instead I would like to see a language with strong flow control or metaprogramming capabilities take on processes as a first class citizen. Perl is probably the closest but still has some warts related to redirection.

The best pattern I have seen is encapsulating business logic into Python or Go and then if really necessary piping it to another script. But, often, if you do this you can just keep the piping internal using data structures.

Unix-pattern facilities work very well for interactive use, which tends to be simple, exploratory, and trial-and-error. But a project's build script may not be simple.

Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @03:24AM (#21014068)
Perl was literally born because Larry Wall reached the limits of what could be done with a combination of Shell + C + Unix utils.

In fact this is how Perl 1 looks: https://st.aticpan.org/source/RCLAMP/perl-1.0_16/

https://github.com/Perl/perl5/commit/8d063cd8450e59ea1c611a2...

Re:Pure Bash Bible by hnlmorg on Thursday September 19, 2019 @06:19AM (#21014900)
If you pardon the shameless self promotion; I'm working on something just like that:

https://github.com/lmorg/murex

It currently has:

* Proper error handling (eg try and catch blocks)

* unit testing and debugging frameworks to help with development and maintainability

* data-type aware, including complex types like how CSV, JSON and YAML are all handled as memory structures and thus the same tools can query any structured data format without understanding it's contents

* while still ostensibly working the same way as a traditional POSIX shell

There's also some work on improving the REPL experience too where I've included:

* automatic man page parsing for flags

* a "tool tip text" like hint line which tells you where commands reside on the fs, what it does, etc. Which is handy if you're trying to debug an existing commend.

* if you paste multiline text into the console you get offered a chance to preview the text before executing it (handy if, like me, you're pretty useless at copy/pasting content reliably)

* a package management system so you know exactly which functions and imported scripts are loaded from which sources (no more "where did that autocomplete suggestion / alias / etc get loaded from?"

There's a few other features like support for events and such like, but they're not yet documented.

The shell is currently beta but I've been using it as my daily driver for about 18 months now. There are still quite a few bugs, plenty of places where code needs to be rewritten for performance and lots of stuff isn't yet documented (though the documentation is pretty good already considering it's only me working on it). So don't expect a finished product. However I do think I'm at the stage where I'm ready for more users to have a play and I welcome PRs, issues raised, general comments and feedback, etc.

# end of shameless self promotion :D

Re:Pure Bash Bible by Crestwave on Friday September 20, 2019 @11:15PM (#21033257)
Seems quite similar to Elvish (https://elv.sh/); have you checked it out?
Re:Pure Bash Bible by hnlmorg on Thursday September 26, 2019 @04:51PM (#21085403)
Sorry, only just seen this comment. Just in case you're still following this thread and interested in a reply:

I'm aware of Elvish and really impressed with what's been built and the traction that has gained. There is definitely some overlap between murex and elvish but also a lot of area's where our shells differ.

I think there is sufficient difference between the two shells to justify their existence.

Re:Pure Bash Bible by Crestwave on Monday October 07, 2019 @03:02AM (#21178183)
Oh, definitely. Just thought it was something you should check out and I didn't see it mentioned anywhere.
Re:Pure Bash Bible by jigglesniggle on Thursday September 19, 2019 @09:47AM (#21016092)
Nice project, look forward to seeing a HN post on it!
Re:Pure Bash Bible by hnlmorg on Thursday September 19, 2019 @11:02AM (#21016836)
Thank you
Re:Pure Bash Bible by al_form2000 on Thursday September 19, 2019 @05:28AM (#21014646)
> Perl is probably the closest but still has some warts related to redirection.

I wholehartedly agree on perl but can you expand on the redirection warts? I seldom had problems with perls' FHs, while, on the contrary I seem to be unable to wrap my head around the contorted syntax involved in bash's handling of descriptors - especially when more than 2 handles are involved.

Re:Pure Bash Bible by jigglesniggle on Thursday September 19, 2019 @09:43AM (#21016062)
Well -- I was comparing Perl to Python in this case. There is roughly the same amount of boilerplate and both are easier to read than bash's redirection.

The wart is that you need IPC::Open3 or equivalent because Perl's intrinsics can not synthesize the pipe operator (though you will think that they can) if you need to insert yourself into the middle of a chain of commands.

Nowadays there are decent wrappers for calling Open3 but more commonly you just find people running one half of the command, buffering the output, and passing it to the second half.

Re:Pure Bash Bible by al_form2000 on Thursday September 19, 2019 @12:46PM (#21017992)
Aw, right. I'd forgotten about IPC::Open3. Because I did not want to think about it, mostly (and so, I usually do exactly what you say people do :-) )
Re:Pure Bash Bible by danielecook on Thursday September 19, 2019 @02:36AM (#21013851)
My mistake - I managed to completely misinterpret what you meant. I agree with your comment!
Re:Pure Bash Bible by Evanbenn on Thursday September 19, 2019 @04:32AM (#21014406)
I think tcl is exactly in this niche. I haven't had time or an excuse to learn it, but it seems to fit perfectly. Haven't yet found out why it seems to be dying away
Re:Pure Bash Bible by blacksqr on Thursday September 19, 2019 @04:35PM (#21020464)
Following page has Tcl code written by antirez to create command pipes:

https://wiki.tcl-lang.org/page/Pipeline+programming

Re:Pure Bash Bible by blacksqr on Thursday September 19, 2019 @04:39PM (#21020511)
A collection of pipeline programming implementations in Tcl:

https://wiki.tcl-lang.org/page/Commands+pipe

Re:Pure Bash Bible by lostmsu on Thursday September 19, 2019 @03:36AM (#21014141)
So PowerShell then?
Re:Pure Bash Bible by marcosdumay on Thursday September 19, 2019 @08:35AM (#21015547)
PowerShell removes the pomp from running processes and adds it squared into running normal functions.
Re:Pure Bash Bible by iamnotacrook on Thursday September 19, 2019 @04:31AM (#21014405)
Isn't that Windows only?
Re:Pure Bash Bible by cannam on Thursday September 19, 2019 @04:56AM (#21014508)
Not any more: https://github.com/PowerShell/PowerShell/releases/

I quite like Powershell on Windows, but I'm not sure I dare try it on Linux. I think it might make my head explode.

Re:Pure Bash Bible by iamnotacrook on Thursday September 19, 2019 @07:54AM (#21015334)
It's quite clear Microsoft are only a couple of years from either an official linux distro or some halfway house of using a linux kernel internally for major os functionality, so it makes little sense learning some new(ish) shell when you could just use bash (via wsl or whatever).
Re:Pure Bash Bible by meloentje on Thursday September 19, 2019 @04:54AM (#21014503)
No, but I haven't seen many Linux users (admitting to) using it.
Re:Pure Bash Bible by sambe on Thursday September 19, 2019 @03:18AM (#21014045)
The overhead of repeatedly launching subshells/processes to do simple operations can add up quickly, especially if it is happening in loops or in parallel. Yes, you shouldn't be using bash for performance, we all know that. But scripts often grow over time and suddenly are found to be slow/resource hogs. I have seen people demand that proper logging be added to a bash program and it then get minutes behind because of the overhead of all the processes called to do the logging. I was able to make that 10000x faster using pure bash.

As to why people like it: it often feels more natural when you are automating what you would type interactively. Unix pipes/coreutils/etc. also feel like a better fit when that automation is mostly about connecting other programs (it's the auxiliary stuff that you'd maybe want in pure bash). Reading the subprocess Python documentation does not exactly fill me with joy. I've heard libraries like Plumbum make it a bit neater - but then you have to ask why learn a bunch of new libraries when I already know bash? In the end it's about the best tool for the job. The danger with bash is going too far, especially if you don't actually know it very well.

Re:Pure Bash Bible by sumosudo on Thursday September 19, 2019 @04:13AM (#21014309)
My favourite way to log.. Redirect stdout and stderr ( &> ) into a named pipe ( >() ) running "tee" And get the redirect into the log file as well. `exec &> >(tee ${__DIR}/${DOC_LOCAL}/${LOG_LOCAL})`
Re:Pure Bash Bible by lordfoo on Thursday September 19, 2019 @07:10AM (#21015126)
Would you mind expanding on this with an example? I'm trying to improve performance of my bash logging
Re:Pure Bash Bible by sumosudo on Friday September 27, 2019 @08:39AM (#21091225)
So this line only redirects all script output to a file as well as ensure that that output makes it onto your screen at the same time.

It is unstructured only in the way you allow any running command within your script to dump their output.

I run most commands inside my scripts with `> /dev/null 2>&1` and then rely on exit codes to wrap structured information to be echoed out with this function:

echo_l(){echo;echo '--------';echo "${1}";echo '--------';echo}

Or functions such as this to populate a log:

log_cat(){echo "${1}" >> ${__LOG} }

But the tee named pipe is the winner.

PS. The __DOC_LOCAL and __DIR variables start with these magic variables below. These variables are a life saver and allow easy directory and file manipulation, they kind of setup a top-level context:

# Set magic variables for current file & dir

__DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

__FILE="${__DIR}/$(basename "${BASH_SOURCE[0]}")"

__SCRIPT="$(basename ${__FILE})"

__BASE="$(basename ${__FILE} .sh)"

__ROOT="$(cd "$(dirname "${__DIR}")" && pwd)"

Re:Pure Bash Bible by unixhero on Thursday September 19, 2019 @08:01AM (#21015358)
+1. My goal is to learn how to robustly do any logging whatsoever. Eager to learn new tricks.
Re:Pure Bash Bible by flukus on Thursday September 19, 2019 @11:27PM (#21023088)
Do you just want to log the scripts execution or do you want something more structured? If it's the former you can redirect the output from within the bash script with this (apologies for any condescension, I'm not familiar with your skill tree):

  if [ ! -t 1 ]; then
    exec > /my/log/file 2>&1
  fi
The if statements tests if your at an interactive prompt, if your not all output from the script get's redirected to /my/log/file. The above poster is instead redirecting into a subprocess " > (tee)" that will both print the output and log it.

It should be noted that often the bottleneck is the terminal itself, try running your scripts with a "> /dev/null" to suppress output and verify the slow part is actually the script.

Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @01:48AM (#21013635)
> I see doing anything but launching programs with simple text-substituted arguments as too much for bash or sh

I would heartily agree. If your shell script grows beyond half a dozen commands or so, you're probably better off rewriting it in just about anything. Python, ruby, go (gorun), rust (cargo-script), or whatever else, doesn't really matter as long as it's not shell.

Re:Pure Bash Bible by dvfjsdhgfv on Thursday September 19, 2019 @02:15AM (#21013757)
Re:Pure Bash Bible by daitangio on Thursday September 19, 2019 @03:10AM (#21014008)
I am slowing moving from bash to python for my utility script. I was unable to love Perl, I think this weired syntax is a very bad choice.

Anyway bash is still faster to use, and a lot of Unix services are based on it. The book is well written and have a great added value. Thank you for sharing!!

Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @05:58AM (#21014788)
>>I think this weired syntax is a very bad choice.

Ah, the luxury the modern breed of programmers enjoy today makes me feel jealous. In these days of Splunk and Document databases(returning jsons and xmls) its hard to understand why so many things in the past were the way they were.

Apart from DBMS interaction(Perl had DBI/x modules for that), pretty much every thing in the decade of 80's even upto late 2000's(tons of legacy systems) was so non standardized that people were literally parsing through log files and non standard data formats to store/exchange a lot of things, this was when the internet was growing crazy year over year, systems needed to be built and put in place. This means you really need to have first class facilities to manipulate text. You needed regexes baked neatly into the language. You needed qw, you needed ``, you needed while<FILEHANDLE>, you needed binary file handling features, you needed string manipulation facilities that could help you drill through any text file you could imagine, you needed powerful functional programming features, you needed OO etc etc. And you needed to get this done under tough deadlines on slow machines. Remember Java being cross platform compliant was one of the biggest selling point of the day. Perl had this before Java.

I personally worked on building a store using rcs and perl, that could store versioned config files, almost like a document data base. The parsing facilities required for the application we did demanded nothing short of a tool like Perl.

Python, and also Java growing rapidly once the data exchange formats were reduced to mark up languages and JSON. Suddenly you could with a library what most Perl programmers were doing using their language powers.

Also look at the Human Genome Project and Perl usage there.

Re:Pure Bash Bible by collyw on Thursday September 19, 2019 @08:09AM (#21015401)
Perl's Tie::DBFile is still the lowest effort data persistence I have seen.

https://perldoc.perl.org/DB_File.html#A-Simple-Example

Re:Pure Bash Bible by collyw on Thursday September 19, 2019 @06:24AM (#21014926)
I do Python more or less full time these days, but bash replacements are the things that I get Perl out for. It has so much more syntactic sugar that makes them better than Python. Python is better for proper applications. Perl is better for one off scripts for manipulating the underlying system.
Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @03:01AM (#21013969)
Inability to use tools like Perl and Emacs is the biggest reason why I have to often break the bad news to people that their week to month long projects(Typically in Python and Java) can likely be done if a few minutes to a day or two, if they knew how to Emacs or Perl well.

Programmers take great pride in freeing accountants and ware house workers from drudgery. But seldom do we look at our work in the same way.

In the real world, most software work is done very similar to digging coal mines with shovels. Laborious manual hand typing jobs.

Re:Pure Bash Bible by unionpivo on Thursday September 19, 2019 @05:23AM (#21014615)
ehh, I agree that its usually faster do do stuff in perl than in python, but if someone spent weeks doing something in python, that could be done in few minutes of perl, python is not the problem. And would probebly take them weeks to do it in perl as well.

There are things you can do in line of perl that will take you 5 -10 min in python, but once program goes above one liners, difference is not that big.

And of course, if you learned vim instead of emacs, you would be even faster :))

Re:Pure Bash Bible by harry8 on Thursday September 19, 2019 @02:27AM (#21013816)
Yeah perl was nice when we were allowed to use that. Why doesn't python have something like named pipes?

    f = open("ls|", "r)
    f.read()
    f.close()
Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @02:45AM (#21013887)
I'm not sure what that's supposed to do, but subprocess provides these facilities, although definitely in a more verbose way.

    f = Popen('ls', stdout=PIPE).stdout
    f.read()
    f.close()
alternatively given this exact behaviour:

    run('ls', stdout=PIPE).stdout
Re:Pure Bash Bible by harry8 on Thursday September 19, 2019 @03:10AM (#21014007)
yeah sure subprocess.check_output(). If you ever dealt with much perl you know how much more pleasant and easy launching processes was in that language - like shell. Python is great, I'm not on the "bash python" wagon. Launching processes, getting the output, munging it and shoving it at another process is more fiddly and less natural in python. If you want to use that as evidence that I'm a garbage developer go ahead, I realise I'm not writing a carefully researched paper here with examples.

In Perl you literally took the part of your shell pipeline, quoted it and opened it like any other file.

    ./output_generator | wc -l
    becomes

    open(SRC, "output_generator|");
    open(WC, "|wc -l);
And you do whatever you want with those filehandles. It's been ages since I wrote any perl. I miss it.
Re:Pure Bash Bible by ThePadawan on Thursday September 19, 2019 @03:21AM (#21014056)
You might like the python "sh" library [0]. It's not perfect, but it sure does remove the visual noise around subprocess.

[0] https://amoffat.github.io/sh/

Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @03:31AM (#21014113)
> yeah sure subprocess.check_output()

It's deprecated and does something quite different.

> If you ever dealt with much perl you know how much more pleasant and easy launching processes was in that language - like shell.

I'm sure it is, but you're missing my point.

> If you want to use that as evidence that I'm a garbage developer go ahead

Well that escalated quickly.

> open(SRC, "output_generator|");

> open(WC, "|wc -l);

>

> And you do whatever you want with those filehandles.

Again python does roughly the same, just with more overhead: a trailing pipe is an "stdout=PIPE", an input is a "input=<whatever>", and you access / forward stdout explicitly:

    src = Popen('output_generator', stdout=PIPE)
    wc = Popen(['wc', '-l'], input=src.stdout)
And as the sibling notes, for shell replacements you can use the sh library to lower the syntactic overhead of popen.
Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @03:02AM (#21013976)
Doesn't scale well when you have to stitch more than two commands with pipes, which is a very common use case for Unix CLI utilities.
Re:Pure Bash Bible by laurieodgers on Thursday September 19, 2019 @03:25AM (#21014086)
I found this problem as well when doing a direct port including pipes from bash to python. It was the first iteration into python and I was lacking time to do a proper port into python native.

The python code to do piping ends up as longwinded and the plumbing of pipes ends up a massive headache so I wrote tidycmd to overcome that issue https://github.com/laurieodgers/tidycmd

Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @03:25AM (#21014084)
Don't see why it "doesn't scale well", the overhead is roughly constant: use the stdout of one program as the input of the next.
Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @03:40AM (#21014168)
That's not as easy as

    cat something | grep "this" | cut -f 1 | sed -e 's/.../.../' 
You end up writing too much code, it's very verbose. Some times symbols are what you want. In fact the biggest progress in the growth of Math happened when they tossed out doing math with words and bought in symbols.
Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @03:54AM (#21014229)
> That's not as easy as

> cat something | grep "this" | cut -f 1 | sed -e 's/.../.../'

Literally none of this is actually useful if you're already in Python:

    (
        line.split('\t')[0].replace(…, …)
        for line in open('something')
        if 'this' in line
    )
> You end up writing too much code

I can believe that if you're calling to external processes to perform operations which are pretty much trivial in the language.

Re:Pure Bash Bible by kamaal on Thursday September 19, 2019 @11:14AM (#21016957)
Of course, if you plan to use one $language alone, you can do anything in that $language.

This question is specific to pipes.

Re:Pure Bash Bible by masklinn on Thursday September 19, 2019 @12:56PM (#21018096)
> Of course, if you plan to use one $language alone, you can do anything in that $language.

That's missing what I'm noting though, which is that you don't need pipes anywhere near a shell script if you can simply do more of your work in-language. Case in point being that the entire pipeline you cited as an issue has no reason to exist outside of a shell or shell script.

Re:Pure Bash Bible by kamaal on Friday September 20, 2019 @12:23AM (#21023315)
That's because regexes are an another pain in Python, You have to write a lot of boiler plate exception handling code. Plus the same boiler plate code for file operations.

It doesn't feel like the language was designed for these tasks.

Re:Pure Bash Bible by Too on Saturday September 21, 2019 @01:51PM (#21036801)
You forgot setting -e and -o pipefail. In case "something" is missing or can't be read for some other reason, your script will just continue happily without warning.

But oh, if you do set -o pipefail the grep will stop the whole pipeline when none of the lines matches "this". So you have to keep fiddling with ${PIPESTATUS[0]}. And none of pipefail or PIPESTATUS are really portable.

Not so simple after all.

Re:Pure Bash Bible by grewil2 on Thursday September 19, 2019 @03:11AM (#21014014)
Yes, Python is the Cobol of script languages.
Re:Pure Bash Bible by hosteur on Thursday September 19, 2019 @08:42AM (#21015603)
What? Why?
Re:Pure Bash Bible by autoexec on Thursday September 19, 2019 @03:03AM (#21013979)
I started out with bash scripts and .bat files and eventually found perl to be the ideal solution to 99% of what I needed as well. I'm still using it for log file parsing and day to day administrative tasks, but I'm starting to pick up python because that seems to be where everyone has agreed to move to.
Re:Pure Bash Bible by Crinus on Thursday September 19, 2019 @06:30AM (#21014951)
One reason i prefer Bash (and i mean Bash not just any shell) is that it tends to stay stable - scripts written years ago work just fine today. These days i mainly use Bash on Windows (via MSYS2) and really it is available pretty much everywhere, either out of the box or via installation.

If anything code that i used to write in Python at the past i write it in Bash nowadays, exactly because Bash has a better record when it comes to not breaking stuff. Though it helps that my Python use is also mostly scripts meant to run from the shell.

Re:Pure Bash Bible by al_form2000 on Thursday September 19, 2019 @01:59AM (#21013686)
Yes - and no. I find the shell is a useful glue language for procedural tasks (do this, run P1, then P2, and if blah) which can/had better be logically simple but rather long and heavy on the system interaction side.

For these, being able to avoid the various $(echo... |sed) can be refreshing. Beside, the book makes for a nice repository of techniques.

Re:Pure Bash Bible by davedx on Thursday September 19, 2019 @03:18AM (#21014044)
I use nodejs. Sometimes it's a case of "go with what you know" rather than "use the best tool for the job". I have too many other things to do for me to bother learning yet another language just for command line scripting.
Re:Pure Bash Bible by letusnot on Thursday September 19, 2019 @08:08AM (#21015398)
I recently started working a more devops role at a company (I've been a ruby dev for most of my career) and one of the things that I've noticed is how _insane_ scripting by ops people is. I'll start poking around a build pipeline and there will all sorts of tortured usages of sed and jq and bash and coreutils to get things done that would be _really_ simple in ruby. I routinely see people using wget and curl in the same script. I'll see people pipe sed text replacement into perl for more text replacement. I'm constantly aware of ruby three liners that are fully portable, even to Windows, that could replace a dozen lines of potentially subtly buggy shell scripting.

And honestly I can't see any good argument for this patchwork approach to gluing things together. I guess some ops people might argue that you'd have to have ruby everywhere but the counter argument would be that we use docker images for everything and adding ruby as a dependency isn't any worse than all the insane dependency gymnastics it takes to get our node apps working.

And all of this applies equally for any language with a reasonable standard library (python, perl). I think people have weird feelings about using bash or make or whatever to accomplish things, like they are riding closer to the metal or that they are living some deeply pragmatic zen Unix philosophy, but mostly they are making an un-testable mess until it works once and then, if they are lucky, they don't have to touch it again.