[tz] [PATCH 3/3] tzselect: use /bin/sh by default
Mike Frysinger
vapier at gentoo.org
Sat Oct 27 09:06:57 UTC 2012
On Saturday 27 October 2012 04:29:57 Joseph S. Myers wrote:
> On Sat, 27 Oct 2012, Mike Frysinger wrote:
> > In looking through tzselect, I can't see any functionality that isn't
> > covered by the POSIX shell spec. Since we're modernizing, change this
> > to use /bin/sh by default.
>
> The "select" builtin is not POSIX.
hmm, so it isn't.
would people be against re-using $@ and manually outputting the list ? here's
a quick hack. it could be made simpler if we set clear limits on what is fair
game ... would be SuSv3 be asking too much ?
-mike
diff --git a/tzselect.sh b/tzselect.sh
index 40134d8..73fa1ff 100755
--- a/tzselect.sh
+++ b/tzselect.sh
@@ -82,6 +82,21 @@ case $(echo 1 | (select x in x; do break; done) 2>/dev/null) in
esac
+# Set up the continent choices.
+set -- \
+ Africa \
+ Americas \
+ Antarctica \
+ 'Arctic Ocean' \
+ Asia \
+ 'Atlantic Ocean' \
+ Australia \
+ Europe \
+ 'Indian Ocean' \
+ 'Pacific Ocean' \
+ 'none - I want to specify the time zone using the Posix TZ format.'
+
+
# Begin the main loop. We come back here if the user wants to retry.
while
@@ -97,30 +112,36 @@ while
echo >&2 'Please select a continent or ocean.'
- select continent in \
- Africa \
- Americas \
- Antarctica \
- 'Arctic Ocean' \
- Asia \
- 'Atlantic Ocean' \
- Australia \
- Europe \
- 'Indian Ocean' \
- 'Pacific Ocean' \
- 'none - I want to specify the time zone using the Posix TZ format.'
+ while :; do
+
+ c=1
+ while [ $c -le $# ]
do
- case $continent in
- '')
- echo >&2 'Please enter a number in range.';;
- ?*)
+ [ $c -lt 10 ] && b=' ' || b=
+ eval echo \""$b$c) \${$c}"\" >&2
+ c=$(expr $c + 1)
+ done
+ echo '#?' | tr '\n' ' '
+ read continent
+ case $(echo "$continent" | tr -d '[0-9]') in
+ '')
+ if [ $continent -gt 0 -a $continent -le $# ]; then
+ eval continent=\""\${$continent}"\"
case $continent in
Americas) continent=America;;
*' '*) continent=$(expr "$continent" : '\([^ ]*\)')
esac
break
- esac
+ else
+ echo >&2 'Please enter a number in range.'
+ fi
+ ;;
+ *)
+ echo >&2 'Please enter a valid number.'
+ esac
+
done
+
case $continent in
'')
exit 1;;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://mm.icann.org/pipermail/tz/attachments/20121027/16425d81/attachment.bin
More information about the tz
mailing list