Simon Willison: TILs on bash

Atom feed for bash

bash A shell script for running Go one-liners - 2023-08-20

bitfield/script is a really neat Go project: it tries to emulate shell scripting using Go chaining primitives, so you can run code like this: …

bash Running multiple servers in a single Bash script - 2023-08-16

I spotted this script that starts the opendream appication running both a Python uvicorn server and a npm run start script and it intrigued me - was it this easy to have a single Bash script run two servers? They were both started in the background with &, like this: …

bash Start, test, then stop a localhost web server in a Bash script - 2022-12-17

I wanted to write a bash script that would start a Datasette server running, run a request against it using curl, then stop the server again. …

bash Ignoring errors in a section of a Bash script - 2022-06-27

For simonw/museums#32 I wanted to have certain lines in my Bash script ignore any errors: lines that used sqlite-utils to add columns and configure FTS, but that might fail with an error if the column already existed or FTS had already been configured. …

bash Using awk to add a prefix - 2022-04-08

I wanted to dynamically run the following command against all files in a directory: …

bash nullglob in bash - 2022-02-14

I ran into a tricky problem while working on this issue: the following line was behaving in an unexpected way for me: …

bash Finding CSV files that start with a BOM using ripgrep - 2021-05-28

For sqlite-utils issue 250 I needed to locate some test CSV files that start with a UTF-8 BOM. …

bash Skipping CSV rows with odd numbers of quotes using ripgrep - 2020-12-11

I'm working with several huge CSV files - over 5 million rows total - and I ran into a problem: it turned out there were a few lines in those files that imported incorrectly because they were not correctly escaped. …

bash Escaping a SQL query to use with curl and Datasette - 2020-12-08

I used this pattern to pass a SQL query to Datasette's CSV export via curl and output the results, stripping off the first row (the header row) using tail -n +2. …

bash Escaping strings in Bash using !:q - 2020-10-01

TIL this trick, via Pascal Hirsch on Twitter. Enter a line of Bash starting with a # comment, then run !:q on the next line to see what that would be with proper Bash escaping applied. …

bash Looping over comma-separated values in Bash - 2020-09-01

Given a file (or a process) that produces comma separated values, here's how to split those into separate variables and use them in a bash script. …