From 9019cf2fa7b6b42bebfb688c1b488aa194650a80 Mon Sep 17 00:00:00 2001 From: The_miro Date: Tue, 14 Jul 2026 09:03:47 +0200 Subject: [PATCH] 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 --- txt2printr.sh | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/txt2printr.sh b/txt2printr.sh index c790fda..17f88b5 100755 --- a/txt2printr.sh +++ b/txt2printr.sh @@ -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