title: Bash get php versions available for apache
body: <p>I want to get a list of all versions of PHP that have the apache module installed.</p>
  <p>This is my function :</p>
  <pre class="lang-sh prettyprint-override"><code>availableVersions () {
      available_versions=&quot;&quot;;
  
      for php_version in `ls -d /etc/php/*/apache2`
      do
          available_versions=&quot;${available_versions}| ${php_version} &quot;;
      done
  
      echo $available_versions;
  }
  </code></pre>
  <p>The return of function is :</p>
  <pre class="lang-sh prettyprint-override"><code>| /etc/php/7.0/apache2 | /etc/php/7.1/apache2 | /etc/php/7.2/apache2 | /etc/php/7.3/apache2 | /etc/php/7.4/apache2 | /etc/php/8.0/apache2
  </code></pre>
  <p>But what i want is :</p>
  <pre class="lang-sh prettyprint-override"><code>| 7.0 | 7.1 | 7.2 | 7.3 | 7.4 | 8.0
  </code></pre>
  <p>Here is a solution that I have just found, but it will have to be improved.</p>
  <pre class="lang-sh prettyprint-override"><code>availablesVersions () {
      available_versions=&quot;&quot;;
  
      for php_version in `ls -d /etc/php/*/apache2`
      do
          version=&quot;${php_version///etc/''}&quot;;
          version=&quot;${version///php/''}&quot;;
          version=&quot;${version///apache2/''}&quot;;
          version=&quot;${version////''}&quot;;
  
          available_versions=&quot;${available_versions}| ${version} &quot;;
      done
  
      echo $available_versions;
  }
  </code></pre>
  <p>Can someone help me?</p>