fix: correct printer device priority fallback in txt2printr.sh

-f only matches regular files, so it never matched the /dev/lp0 or
/dev/usb/lp0 character device nodes, leaving dev unset and always
failing. Use -e existence checks in proper if/elif priority order
(lp0 > usb/lp0 > stdout), with PRINTER_DEV as an unconditional override.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
master
Amir Alexander Abdelbaki 2026-07-14 09:03:47 +02:00
parent adf5a6ec84
commit 9019cf2fa7
1 changed files with 8 additions and 13 deletions

View File

@ -10,21 +10,16 @@ infile="${1:-ascii-img.txt}"
# Posted by John Feminella, modified by community. See post 'Timeline' for change history
# Retrieved 2026-07-14, License - CC BY-SA 4.0
if [ -f /dev/lp0 ]; then
dev="${PRINTER_DEV:-/dev/lp0}"
if [ -n "$PRINTER_DEV" ]; then
dev="$PRINTER_DEV"
elif [ -e /dev/lp0 ]; then
dev=/dev/lp0
elif [ -e /dev/usb/lp0 ]; then
dev=/dev/usb/lp0
else
dev=/dev/stdout
fi
if [ -f /dev/usb/lp0 ]; then
dev="${PRINTER_DEV:-/dev/usb/lp0}"
fi
if [ ( ! -f /dev/lp0 ) && ( ! -f /dev/usb/lp0 )]; then
dev="${PRINTER_DEV:-/dev/stdout}"
fi
if [ ! -f "$infile" ]; then
echo "txt2printr: file not found: $infile" >&2
exit 1