[tz] [PATCH 1/4] tzselect: Replace Korn/Bash-only select construct.

Paul Eggert eggert at cs.ucla.edu
Sun Oct 6 19:34:20 UTC 2013


Patrick 'P. J.' McDermott wrote:

> As far as I could tell, the output of my select replacement function was
> exactly the same as that of the select construct of bash and ksh93.

'select' generates multicolumn output whereas the replacement is
always single-column.  Multicolumn is nicer on smaller displays.

> A "${##}" expansion would have been better than what I proposed.

Unfortunately Solaris /bin/sh doesn't support that.

>> +	  printf "%${select_width}d) %s\\n" $select_i "$select_word"
>> +	done ;;
>
> Shouldn't this print to stderr?

Yes, thanks for catching that.  I pushed this further patch:

>From 0f9614ba9e3a5afbf667231d8dbb6ab3b5df6354 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert at cs.ucla.edu>
Date: Sun, 6 Oct 2013 12:28:30 -0700
Subject: [PATCH] * tzselect.ksh (doselect): Prompt to stderr, not stdout.

(Thanks to Patrick 'P. J.' McDermott.)
---
 tzselect.ksh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tzselect.ksh b/tzselect.ksh
index 47c67bd..9d70691 100644
--- a/tzselect.ksh
+++ b/tzselect.ksh
@@ -119,7 +119,7 @@ else
 	for select_word
 	do
 	  select_i=`expr $select_i + 1`
-	  printf "%${select_width}d) %s\\n" $select_i "$select_word"
+	  printf >&2 "%${select_width}d) %s\\n" $select_i "$select_word"
 	done ;;
       *[!0-9]*)
 	echo >&2 'Please enter a number in range.' ;;
@@ -133,7 +133,7 @@ else
       esac
 
       # Prompt and read input.
-      printf %s >&2 "${PS3-#? }"
+      printf >&2 %s "${PS3-#? }"
       read select_i || exit
     done
   }
-- 
1.8.1.2




More information about the tz mailing list