Live data from Hacker News

Pure Bash Bible

github.com

101–110 of 258 posts

Re: Pure Bash Bible

#101
post #44

Earlier quoted context omitted.

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…

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})`

Would you mind expanding on this with an example? I'm trying to improve performance of my bash logging

Re: Pure Bash Bible

#102
post #91

Earlier quoted context omitted.

> This reads horrible. Just use the shell function by its descriptive name... The reasons are explained in the foreword: Calling an external process in bash is expensive and excessive use will cause a noticeable slowdown. Scripts and programs written using built-in methods (where applicable) will be faster, require fewer dependencies and afford a better understanding of the language itself.

The slow down caused to any developer that has to try and read that is probably orders of magnitude more worth optimizing for than how fast a bath script runs. I'll take the grep/sed/awk version.

Not defending this particular example, but there are contexts where avoiding an external call can make a difference. Think a script calling an external program in a deeply nested loop. This sort of optimization could be used as a last resort, after identifying a real performance issue and evaluating the possibility of restructuring the code.

Re: Pure Bash Bible

#103
post #91
post #85

Looking at the very first example: trim_string(){ # Usage: trim_string " example string " : "${1#"${1%%[![:space:]]*}"}" : "${_%"${_##*[![:space:]]}"}" printf '%s\n' "$_" } This reads horrible. I see no reason to prefer this over programs like sed, bash is after all a shell, intended firstly for running external programs/commands.

> This reads horrible. Just use the shell function by its descriptive name... The reasons are explained in the foreword: Calling an external process in bash is expensive and excessive use will cause a noticeable slowdown. Scripts and programs written using built-in methods (where applicable) will be faster, require fewer dependencies and afford a better understanding of the language itself.

Sure, but the point of Bash is to run external programs.

Re: Pure Bash Bible

#104

Hello, I'm the author of the Pure Bash Bible. Happy to answer any questions you may have. Here's an example of what bash is capable of: https://github.com/dylanaraps/fff/ (a TUI file manager written in bash)!

[OT] Hi Dylan! Just discovered your project - KISS. I respect you a lot for what you write, and you've been an inspiration at times.

Did you just decide one day that you have to write a distribution from scratch? What was the thought process, and how complicated is it actually. Also, I'd like to contribute if there's a chance.

Re: Pure Bash Bible

#106
post #83
post #63

I write a bash script or two every month so I thought I'm okay. But then came along the very first example: trim_string() { # Usage: trim_string " example string " : "${1#"${1%%[![:space:]]*}"}" : "${_%"${_##*[![:space:]]}"}" printf '%s\n' "$_" } Ok, so the : is somehow a temporary variable... Then there is a variable starting at $ and you lost me :D Can someone break down that line for me? What the hell is going on…

And that's the problem with bash scipting - very quickly it gets very cryptic, difficult to follow and understand without knowing various "clever tricks" and gimmicks. This is all fine and dandy for personal usage but god forbid other developers might need to changes something inside this kind "clever" code.

I feel the code above is clearly a bastardization, which is possible in several languages. Not to discount your point in the many bashisms, but that example is definitely not what's wrong with scripting.

Re: Pure Bash Bible

#107

Hello, I'm the author of the Pure Bash Bible. Happy to answer any questions you may have. Here's an example of what bash is capable of: https://github.com/dylanaraps/fff/ (a TUI file manager written in bash)!

Just some feedback on the sale of the book (which I wanted and probably will buy).

Upon checkout you need to confirm the sale via a email sent to the email address provided by you.

I may be the exception and granted - it's basically due to a very crappy phone on which email ceased to work - but I was not able to finalize the sale since I'm not able to access my private email remotely.

I sent myself the link and will probably give it another shot from home. But you may want to take it up with the seller that there are folks out there for which this is not really a convenient way to close a sale. Especially not after entering valid credit card information.

Re: Pure Bash Bible

#108
post #104

Hello, I'm the author of the Pure Bash Bible. Happy to answer any questions you may have. Here's an example of what bash is capable of: https://github.com/dylanaraps/fff/ (a TUI file manager written in bash)!

[OT] Hi Dylan! Just discovered your project - KISS. I respect you a lot for what you write, and you've been an inspiration at times. Did you just decide one day that you have to write a distribution from scratch? What was the thought process, and how complicated is it actually. Also, I'd like to contribute if there's a chance.

> [OT] Hi Dylan! Just discovered your project - KISS. I respect you a lot for what you write, and you've been an inspiration at times.

Thanks, I appreciate it! :)

> Did you just decide one day that you have to write a distribution from scratch?

Pretty much. I'd been distro hopping for some time and wasn't happy with any of the choices in front of me.

I wanted something that could run without `dbus`, `glibc`, `systemd`, `wayland`, `polkit`, `elogind`, etc etc and none of the other distributions could provide this.

Even Gentoo through their arms in the air when Firefox 69 broke the `--disable-dbus` configure flag (and added a mandatory dependency on `dbus`).

I instead spent the hours patching `dbus` out of Firefox 69 and that's how I ship it in KISS. https://github.com/kisslinux/repo/blob/master/extra/firefox/...

> What was the thought process

Start from zero and build piece by piece questioning each step along the way. Is this needed? Are there alternatives? Can we do this in a "simpler" way? Step away, come back to it later and ask "was this right?", "can we trim back the fat?".

This repeated until things were effectively "done".

> and how complicated is it actually

No piece of software seems to list its (mandatory) dependencies properly so it was a trial and error of figuring out _exactly_ what each piece of software needs.

Looking at other distributions themselves wasn't much help as they list a lot of "optional" dependencies as "required".

There's also no (or very little) documentation online for how to write a package manager or Linux distribution from scratch.

It's been a tedious but rewarding process thus far. I'm talking to you from KISS right now! It feels good to turn on my laptop and be running a distribution I created from scratch. :)

> Also, I'd like to contribute if there's a chance.

Go for it! In terms of contribution there's bug reporting, fixing documentation, adding missing packages, fixing bugs in existing packages etc.

Hop on IRC (#kisslinux @ freenode.net) if you'd like to chat. :)

Re: Pure Bash Bible

#109

Hello, I'm the author of the Pure Bash Bible. Happy to answer any questions you may have. Here's an example of what bash is capable of: https://github.com/dylanaraps/fff/ (a TUI file manager written in bash)!

Just some feedback on the sale of the book (which I wanted and probably will buy). Upon checkout you need to confirm the sale via a email sent to the email address provided by you. I may be the exception and granted - it's basically due to a very crappy phone on which email ceased to work - but I was not able to finalize the sale since I'm not able to access my private email remotely. I sent myself the link and will…

I'll look into also putting the book on Amazon or another "ebook" website. I chose leanpub as it _is_ for books like this but if it does cause issues for people I'll explore my options on other platforms.

Thanks for letting me know and apologies for the inconvenience.

Re: Pure Bash Bible

#110
post #73

Earlier quoted context omitted.

Isn't that Windows only?

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.

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).
Post reply on HN