Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I found some code in one of the answers here and accommodated it to my needs but now I have two questions:

Q1: how can I display the options text after the code in case statement finishes? So the user can see the options again.

Q2: Can I make it so that every option is displayed on its own line when I run the script? Currently it is not.

options=(
        "quit/exit"
    "new rational db"
    "run php for rational codebase"
    "run php for playground codebase"
   )

select option in "${options[@]}"; do
  case "$REPLY" in
       1) break;;
       2) sudo -i -u db2inst1 bash -c "db2stop force;";;
       3) rm /tmp/createDb2*;;
       4)  ;;               
  esac
done
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Q1: add spaces to the end of any of the options to make it longer than 40 characters, for example:

options=(
        "quit/exit"
    "new rational db"
    "run php for rational codebase"
    "run php for playground codebase                       "
   )

Q2: Not sure if there is a more elegant way (didn't see in help select), but this should work:

finished=
while test ! "$finished"; do
    select option in "${options[@]}"; do
      case "$REPLY" in
           1) finished=1;;
           2) sudo -i -u db2inst1 bash -c "db2stop force;";;
           3) rm /tmp/createDb2*;;
           4)  ;;               
      esac
      break
    done
done
share|improve this answer
    
Works nicely, thank you. –  Radek Aug 22 '12 at 5:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.