Prefer tee -a, not >>, in CI(huonw.github.io) Shell scripts sometimes have to append data to a file. Redirecting output with >> is the conventional way and works fine, but using tee -a instead is a usually better default, especially in continuous integration. It’s just as easy and gives automatic introspection: the same value is printed to stdout and so appears in normal logs too.
Find the oldest line in your repo(milofultz.com) This is how all my projects go. I get a wild hare and then figure out how I can make a shell script to do it. Thanks to some help from people online, I was able to make a script that listed out the oldest lines in a git repo. Kind of fun to see what legacy stuff is still around.
63 points by surprisetalk 25 days ago | 58 comments
Today I learned that bash has hashmaps (2024)(xeiaso.net) Hashmaps (associative arrays) are a great way to store a bag of key-value data. At work I was writing something that needed me to spawn a bunch of GPU instances, GPU availability is spread out by region and GPU type. I wanted to store a mapping of GPU kind to region name and for some reason I thought it would be a good idea to do it in bash.
Populating env vars using 1Password(coryd.dev) I love automating things and — with that impulse entirely unchecked — I've written up a shell script to make setting this site up for local development even simpler.
A Second Search for Bash Scripting Alternatives(monzool.net) SHELL SCRIPTING IS something most programmers will encounter often – especially if doing dev-ops, automation and general Linux work. Unfortunately we are mostly stuck with bash. There surely must be better alternatives…
21 points by thunderbong 94 days ago | 49 comments
Resolving a mysterious problem with find(johndcook.com) Suppose you want to write a shell script searches the current directory for files that have a keyword in the name of the file or in its contents. Here’s a first attempt.
Yosild: A single shell script that builds a full, minimal Linux distribution(jm.iq.pl) Yosild is a single shell script that builds a full, minimal Linux distribution, based on BusyBox. It compiles the latest stable kernel and the latest stable version of the BusyBox. This script can prepare minimalistic Linux system for devices with little hardware resources. Yosild Linux needs just 70 MB RAM and 40 MB storage size. yosild.sh requires minimal Debian or Ubuntu distro to run with the architecture compatible with the target device.
40 points by ocean_moist 105 days ago | 0 comments
Learn Awk in Y Minutes(learnxinyminutes.com) AWK is a standard tool on every POSIX-compliant UNIX system. It’s like flex/lex, from the command-line, perfect for text-processing tasks and other scripting needs. It has a C-like syntax, but without mandatory semicolons (although, you should use them anyway, because they are required when you’re writing one-liners, something AWK excels at), manual memory management, or static typing. It excels at text processing. You can call to it from a shell script, or you can use it as a stand-alone scripting language.
Abuse ZSH Parameter Expansion to Expand GNU-Style Arguments(blogspot.com) This method offers exactly one benefit: the target platform I was working with for this project was mingw under Windows and, like WSL1, it had this very painful performance issue when a shell had to create a sub-shell -- basically, any time you $(run something) and that means "if your function returns anything except for an integer", it's going to have a serious cost to place that into a variable the convenient way.
338 points by lukastyrychtr 138 days ago | 128 comments
A Tour of Hell – Shell scripting Haskell dialect(chrisdone.com) This set of slides sketches out the implementation of Hell, in technical detail. I do tend to switch between the slides, old code, and the present code, so bear with me. It's more about the ideas. If you want to see a complete implementation, the complete implementation of Hell is one file, which you can look through easily.