diff options
author | Zac Medico <zmedico@gentoo.org> | 2006-08-29 21:28:56 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2006-08-29 21:28:56 +0000 |
commit | e12154ee664bc86f51f6b4e339402782d386364c (patch) | |
tree | f6c8f841ec879dd2a4041ce4e4434efc1de7ccaa | |
parent | b2108d58eb2fe043cce935607b7b235c787a83aa (diff) | |
download | portage-e12154ee664bc86f51f6b4e339402782d386364c.tar.gz portage-e12154ee664bc86f51f6b4e339402782d386364c.tar.bz2 portage-e12154ee664bc86f51f6b4e339402782d386364c.zip |
Use a specialized read_int function to read integer input for bug #143881. This uses a subshell to work around bash's tendency to break out of a loop whenever an integer conversion fails.
svn path=/main/trunk/; revision=4375
-rwxr-xr-x | bin/etc-update | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/bin/etc-update b/bin/etc-update index a11babfd2..a02088545 100755 --- a/bin/etc-update +++ b/bin/etc-update @@ -142,7 +142,7 @@ configuration file is followed by a list of possible replacement files." echo " (-5 to auto-merge AND not use 'mv -i')" echo " (-7 to discard all updates)" echo -n " (-9 to discard all updates AND not use 'rm -i'): " - read input + input=$(read_int) else dialog --title "${title}" --menu "${my_title}" \ 0 0 0 $(echo -e "-1 Exit\n$(<${TMP}/menuitems)") \ @@ -190,6 +190,20 @@ function user_special() { return 1 } +function read_int() { + # Read an integer from stdin. Continously loops until a valid integer is + # read. This is a workaround for odd behavior of bash when an attempt is + # made to store a value such as "1y" into an integer-only variable. + local my_input + while true; do + read my_input + # failed integer conversions will break a loop unless they're enclosed + # in a subshell. + echo "${my_input}" | ( declare -i x; read x) && break + done + echo ${my_input} +} + function do_file() { echo local -i my_input @@ -224,7 +238,7 @@ function do_file() { if [[ ${mode} == 0 ]] ; then cat ${TMP}/menuitems echo -n "Please select a file to process (-1 to exit this file): " - read my_input + my_input=$(read_int) else dialog --title "${title}" --menu "${my_title}" \ 0 0 0 $(echo -e "$(<${TMP}/menuitems)\n${fcount} Exit") \ @@ -304,7 +318,7 @@ function do_cfg() { 3) Interactively merge original with update 4) Show differences again Please select from the menu above (-1 to ignore this update): " - read my_input + my_input=$(read_int) fi case ${my_input} in @@ -358,7 +372,7 @@ function do_merge() { 4) Edit merged file 5) Return to the previous menu Please select from the menu above (-1 to exit, losing this merge): " - read my_input + my_input=$(read_int) case ${my_input} in 1) echo "Replacing ${ofile} with ${mfile}" chmod --reference=${ofile} ${mfile} |