last.sh will exit 1 when no file found; handle it in next.sh. meaning um next works in empty dirs

This commit is contained in:
bth 2024-01-22 10:21:53 -08:00
commit cf6ff3349d
6 changed files with 47 additions and 19 deletions

View file

@ -1,3 +1,5 @@
#!/bin/bash
# Get the last file name of any numbered series of text files.
# file format:
@ -6,6 +8,14 @@
# in plain terms:
# [leading numbers with consistent width].[optional string descriptor and . separator][md|txt]
# TODO: signal no file found, so that next knows to create one.
# Grep exits 1, but tail exits 0.
ls | egrep '^[[:digit:]].*\.md|txt' | tail -n 1
UMALLFILES=`ls | egrep '^[[:digit:]].*\.(md|txt)'`
LASTSTATUS=$?
# NOTE: if we don't stop and signal here, tail will exit 0
if [ "$LASTSTATUS" -ne 0 ]; then
echo "no files found" >&2
exit 1
fi
# NOTE: if var isn't quoted echo will change newlines to spaces
echo "$UMALLFILES" | tail -n 1