Simon Willison: TILs on bash

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. …