title: Is there any better way to repeatedly call function for each case statement
body: <p>I wrote a bash script to automate lamp installing in my server, they work great but there's a problem regarding its readability.</p>
  <pre class="lang-sh prettyprint-override"><code>  # Asking if want to install PHP or build from source
    read -p &quot;This script will install PHP, do you want to install it (y/n)?&quot; phpchoice
    case &quot;$phpchoice&quot; in
      [Yy]* ) isinstallphp=yes;;
      [Nn]* ) isinstallphp=no;;
      * ) echo &quot;invalid&quot;;;
    esac
  
    if [ isinstallphp == &quot;yes&quot; ]; then
      # Prompt for php version
      options=(&quot;php5.6&quot; &quot;php7.0&quot; &quot;php7.1&quot; &quot;php7.2&quot; &quot;php7.3&quot; &quot;php7.4&quot; &quot;php8.0&quot; &quot;php8.1&quot;)
      function do_something () {
        echo -e &quot;${Ye}You picked ${Wh}$php_opt${Ye}, will be installing that instead${Nc}&quot;
      }
      select php_opt in &quot;${options[@]}&quot;; do
        case &quot;$php_opt,$REPLY&quot; in
          php5.6,*|*,php5.6) do_something; break ;;
          php7.0,*|*,php7.0) do_something; break ;;
          php7.1,*|*,php7.1) do_something; break ;;
          php7.2,*|*,php7.2) do_something; break ;;
          php7.3,*|*,php7.3) do_something; break ;;
          php7.4,*|*,php7.4) do_something; break ;;
          php8.0,*|*,php8.0) do_something; break ;;
          php8.1,*|*,php8.1) do_something; break ;;
        esac
      done    
    fi
  </code></pre>
  <p>The case statement part where I put <code>do_something</code> function looks messy, all the function do is echo which php option user choose in color. Is there any way to shorten the code ?</p>