I have a script I use to create draft blog posts as I work on them. Recently, I added two fields for post excerpts and tags. However, I get an unbound variable
error when I try to run it. Niether bash -n
or shellcheck
catches this and I assumed set -u
would resolve this internally, but I guess not.
How should this be handled?
#!/bin/bash
set -eu
# Set some variables
export site_path=~/Documents/Blog
drafts_path=~/Documents/Blog/_drafts
title="$1"
# Create the filename
title=$(awk '{print tolower($0)}' <<<"$title")
filename="$title.markdown"
file_path="$drafts_path/$filename"
echo "File path: $file_path"
# Create the file, Add metadata fields
cat >"$file_path" <<EOL
---
title: "$title"
layout: post
excerpt:
tags: []
---
EOL
# Open the file in BBEdit
bbedit "$file_path"
exit 0