======================================================== Select statements vs. Here Documents and Case statements ======================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com The "select" statement first appeared in recent versions of the Korn Shell. While it saves quite a bit of code, it isn't universally available on all flavours of Unix. To write a fully portable shell script, avoid select in favour of script syntax that works everywhere. Example: Using Korn shell "select" syntax (recent Korn shell and bash only): PS3="Select a fruit by number:" select fruit in apple pear banana 'passion fruit' ; do echo "You selected $fruit" break done Using traditional Bourne shell syntax (works on all versions of Unix): # loop until the user enters some non-zero value for $number # number= while [ -z "$number" ]; do cat 1>&2 <<- EOF 1) apple 2) pear 3) banana 4) passion fruit EOF echo 1>&2 "Select a fruit by number:" read number done # see which number the user entered # case "$number" in 1) fruit='apple' ;; 2) fruit='pear' ;; 3) fruit='banana' ;; 4) fruit='passion fruit' ;; *) fruit='' ;; esac echo "You selected $fruit" Evaluate whether the Korn shell syntax is usable in your application, or whether your script should be portable to all versions of Unix.