[tz] [PATCH 1/4] tzselect: Replace Korn/Bash-only select construct.
Patrick 'P. J.' McDermott
pj at pehjota.net
Sun Oct 6 18:21:06 UTC 2013
On 2013-10-06 06:01, Paul Eggert wrote:
> Thanks. That patch had some problems with Solaris 9 /bin/sh,
OK. I don't have access to Solaris 9 /bin/sh, so I couldn't test that.
> and also its output wasn't as nice as that of the builtin
> 'select' command,
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. I
guess I'm not sure what you mean here.
> so I pushed the following patch instead,
> which I hope addresses the issues raised by your first 3
> patches.
Thanks. It looks good (better than what I posted) and works well.
[...]
> +else
> + doselect() {
> + # Field width of the prompt numbers.
> + select_width=`expr $# : '.*'`
Since posting the patch, I realized that the printf and bc pipeline here
was unnecessary. A "${##}" expansion would have been better than what I
proposed.
This expr is also better.
> + select_i=
> +
> + while :
> + do
> + case $select_i in
> + '')
> + select_i=0
> + for select_word
> + do
> + select_i=`expr $select_i + 1`
> + printf "%${select_width}d) %s\\n" $select_i "$select_word"
> + done ;;
Shouldn't this print to stderr?
$ bash -c 'select x in x; do break; done' >/dev/null
1) x
#? 1
$ ksh93 -c 'select x in x; do break; done' >/dev/null
1) x
#? 1
$ dash tzselect.ksh >/dev/null
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
#?
Before this patch, under normal operation the only output on stdout was
the `echo "$TZ"` at the end.
> + *[!0-9]*)
> + echo >&2 'Please enter a number in range.' ;;
> + *)
> + if test 1 -le $select_i && test $select_i -le $#; then
> + shift `expr $select_i - 1`
> + select_result=$1
> + break
> + fi
Good catch; this shift is certainly better than my loop. :)
> + echo >&2 'Please enter a number in range.'
> + esac
> +
> + # Prompt and read input.
> + printf %s >&2 "${PS3-#? }"
> + read select_i || exit
Yes, exit is better here.
> + done
> + }
> +fi
Thanks,
--
Patrick "P. J." McDermott
http://www.pehjota.net/
Lead Developer, ProteanOS
http://www.proteanos.com/
More information about the tz
mailing list