the way of bash (@thewayofbash) header
the way of bash (@thewayofbash) profile picture

bash is a language, and also a religion. Like Jesus, it was bourne again.

Joined February 2019
If the script needs an env var for a single command, instead of: ``` export MYENV=val my_command ``` use this construct: ``` MYENV=val my_command ``` and now MYENV won't bleed to the rest of the script.
1
To find the path of a program, use `type -p` instead of `which`. `type -p` is a built-in command and therefore available everywhere.
The Oil shell project is one of the most extensive re-implementation of Bash out there. Check out @oilshellblog / oilshell.org
5
the way of bash retweeted
direnv v2.23.0 has been released! It adds `direnv fetchurl <URL> [<integrity-hash>]` as a content-addressable wget replacement. And stdlib `source_url <URL> <integrity-hash>` function that can be used to security load bash scripts from the Internet. github.com/direnv/direnv/rel…
1
2
11
ChaCha20 implemented in pure Bash. git.zx2c4.com/chacha20.sh/tr… Thanks @flokli for the link!
2
The Bernstein-chaining version of: bash -c "echo sub command 'need quoting'" Is: bash -c '"$@"' argv0 echo sub command "need quoting" It's a bit more verbose but it avoids having to escape arguments.
3
1
10
The pure Bash bible has made a lot of progress since last posted. It's now a good reference material for day-to-day Bash programming. github.com/dylanaraps/pure-b…
1
10
How to get the $USER in pure bash: : \\u printf '%s\n' "${_@P}" Magic! 1. : \\u -- sets \u to $_ 2. Use @P to expand \u like it was a prompt Works in Bash 4.4+
2
A good default shebang: ``` #!/usr/bin/env bash set -euo pipefail ``` Not everybody has bash installed in /usr/bin/bash. Abort on error. Catch unused variables. Abort if any programs in the pipe fail.
3
Bash is great for writing web servers for mobile apps! github.com/lheckemann/presre…
3
the way of bash retweeted
Wrote about coprocesses in Bash. coproc is a way of spawning a subprocess asynchronously. It lets a shell communicate with the subprocess since the input and output file descriptors are available to the shell. But not without gotchas. medium.com/@copyconstruct/ba…
6
21
1
104
shfmt can be used to format bash scripts: github.com/mvdan/sh
2
Bash is a functional language because pipes are Monads
5
Bash only takes 5.8M on disk. In 2019 it is acceptable for scripts to not be cross-shell compatible and only target bash.
ShellCheck is a bash linter and almost a requirement when writing any script. shellcheck.net/
1
$ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) Copyright (C) 2007 Free Software Foundation, Inc. This is the version that is shipping on MacOS Mojave and is basically useless. Shame on @Apple for shipping a 12 year old software with no upgrades.
1
2