Live data from Hacker News

Pure Bash Bible (2018)

github.com

51–60 of 106 posts

Re: Pure Bash Bible (2018)

#51

Earlier quoted context omitted.

I typically agree, but I don't think its as simple as a "screenful of lines" criteria. I find it useful when most of your work is wiring other command line tools together. When that's most of your work, shell scripting feels like it has the best affordances. Anything that gets too fancy beyond this, with anything that resembles an algorithm or computation, you'll feel real pain :) Bash doesn't even support floating p…

For me this is is it, if you're stringing together a load of other command line tools then a large well structured shell script is perfectly fine. A typical task in my day job is extracting metadata from and transcoding large AV archives, I always use a bash for this because I'm mainly stringing together tools like ffmpeg or sox, making directories, tempfiles, creating chesksum manifests, etc. Also I typically do thi…

> python

There's a library for Node called Zx (https://github.com/google/zx) that provides a more shell-liked interface for Node.

I've been working on something in Python, inspired by Zx and Xonsh (https://xon.sh/), with syntax like this:

  from pathlib import Path

  from pyshell import Pipeline


  args = ["123", "456"]
  f = Path("out.txt")
  with Pipeline() as p:
      p.exec("a") | p.exec("b", *args) | p.exec("c", "x", "y") >> f
Personally, the above would be hugely useful to me in reducing my temptation to write shell scripts, and significantly reducing the annoyance of doing these things in Python.

Is this something you'd use? It's slow going for me because it basically involves writing a compiler and I have approximately zero idea of what I'm doing. Knowing that other people would find it useful helps me stay motivated to keep working on it! Or if someone who theoretically is the primary audience doesn't find it useful, it might mean that I should spend my energy on other things.

Re: Pure Bash Bible (2018)

#52
post #34

dash is significantly faster than bash and lighter weight, too. I added tab completion and use dash as interactive shell as well as scripting shell.

I would argue reaching for the shell to do your scripting is never a good idea, unless your problem is trivial to begin with (e.g. fits in less than a hundred lines of extremely readable and straightforward code). My rule of thumb is: "can I fit it in a one-liner?" - then I refactor it until it's readable, or otherwise use something else. Once you need to do fancy array manipulation, hash tables, data structures, etc…

For 1-liners there are only 2 real non-shell contenders - Perl and Ruby. Yes you can do them with Python but it ain't pretty.

Re: Pure Bash Bible (2018)

#53
post #35

After years writing bash scripts I stumbled with this line... set -e Which forces the script to exit on first error. This line be in the bible as Genesis 1:1

Just wait till you learn about: set -euo pipefail That should be line two of every bash script.

Used it in every script after learning about it. Might be great if it could be set globally for all Bash scripts.

Re: Pure Bash Bible (2018)

#54
With LLMs/ChatGPT, i would prefer fine-tuning a model and have it auto-generate bash commands with my natural language description.

I remember, I used to keep a diary with landline phone numbers of relatives etc. I used to remember at least a dozen of those numbers for emergency. With mobile and digital contacts, now that number is down to just 2.

Wonder, what the programming is going to look like in 10 yrs. If no-one dedicates so much of their time and effort to document, the programmers then would feel helpless. right?

1. Or at that point, LLMs will be intelligent enough to read the source code and figure out the commands.

2. They can generate data by running commands, and train themselves using this simulated data.

What other scenarios will occur once we stop generating data using human effort because we all are so dependent on LLMs to generate those commands?

Re: Pure Bash Bible (2018)

#55
post #28

Earlier quoted context omitted.

https://news.ycombinator.com/item?id=35768615 Perhaps dash now has these features but does NetBSD sh or FreeBSD sh have them. What's the point of "pure sh" if it's restricted to specific versions of shells. Opinions may differ but I'd rather learn the "lowest common denominator". I use the same scripts on both Linux and BSD so I need portability. I do not use bash for scripting. It's larger and slower. One source I c…

> and slower. I like to write posix sh scripts for the sake of portability and, funnily enough, future proofing as I don't like having to maintain stuff against changes that break compatibility, which is something bash does (archlinux is still on an older bash even though debian stable has the latest, because bash 5.2 broke some of archlinux's own scripts. This is why you should not write bash scripts.), but bash bei…

Can you elaborate on your last point? I've never had a problem scripting with Ruby.

Re: Pure Bash Bible (2018)

#56
I always hear people talk about writing portable, POSIX compliant shell scripts so they'll work in more environments (assuming those environments are needed, of course), but how often do you run into an environment where you don't have a fairly complete version of Bash available? Genuine open question, I'd be really interested to know what that situation is. Lean container images, embedded, older systems? I'm really curious.

Re: Pure Bash Bible (2018)

#57
post #54

With LLMs/ChatGPT, i would prefer fine-tuning a model and have it auto-generate bash commands with my natural language description. I remember, I used to keep a diary with landline phone numbers of relatives etc. I used to remember at least a dozen of those numbers for emergency. With mobile and digital contacts, now that number is down to just 2. Wonder, what the programming is going to look like in 10 yrs. If no-on…

There's a middle ground alternative where the LLM can read the source, give you a high level description (aka documentation), plus cite the relevant parts of the code. Fingers crossed.

Re: Pure Bash Bible (2018)

#58

Earlier quoted context omitted.

What could go wrong? Use a technology that is notorious for outputting wrong information to write a script that is really hard to get it right and then later reviewed by someone that can’t really understand it. At this point just use something else.

You say that likes writing code doesn’t involve experimentation in general. You can’t trust the code that that Chatgpt gives you, but you also can’t trust the code that even you write until you test it. It is always an iterative process. Why does it matter that some use AI tools as a starting point?

> Why does it matter that some use AI tools as a starting point?

I rather learn (or iterate) using a proper source of information (like a book, a blog post written by someone with actual knowledge, or even with a more experience coleague). At least for me it seems more productive.

Re: Pure Bash Bible (2018)

#59

Earlier quoted context omitted.

For me this is is it, if you're stringing together a load of other command line tools then a large well structured shell script is perfectly fine. A typical task in my day job is extracting metadata from and transcoding large AV archives, I always use a bash for this because I'm mainly stringing together tools like ffmpeg or sox, making directories, tempfiles, creating chesksum manifests, etc. Also I typically do thi…

> python There's a library for Node called Zx ( https://github.com/google/zx ) that provides a more shell-liked interface for Node. I've been working on something in Python, inspired by Zx and Xonsh ( https://xon.sh/ ), with syntax like this: from pathlib import Path from pyshell import Pipeline args = ["123", "456"] f = Path("out.txt") with Pipeline() as p: p.exec("a") | p.exec("b", *args) | p.exec("c", "x", "y") >>…

This looks cool, especially if one needed to do a number of pipe operations from python, I'm not sure of an elegant way to do that already.

Honestly I might be the wrong audience though, I've spent many years shell scripting and I find the flexibility of using the command line tools so great I choose to use it first despite the inadequacies of bash. I wonder if users with my point of view would ever be tempted away.

Also the shell is an interactive repl, which to me is where a lot of the power lies. The number of times I've asked a junior things like what the total duration of a set of audio files is, or the average length or something. They often come back with a python script or worse a jupyter notebook and pandas. The answer can also often be found by combining things like grep and awk in a few seconds once you've become acquainted with the tools, I guess I do try and demonstrate / preach this where I can.

Re: Pure Bash Bible (2018)

#60
post #35

After years writing bash scripts I stumbled with this line... set -e Which forces the script to exit on first error. This line be in the bible as Genesis 1:1

Just wait till you learn about: set -euo pipefail That should be line two of every bash script.

POSIX shells only support: set -eu

You might want to be in the dash POSIX shell for raw speed and portability.

Post reply on HN