I am trying to understand why a bash script seems to stop its execution at an if statement. I have added echo statements in the scripts.

I have a first batch called make.sh:


export LIB_DIR=${ROOT_DIR}/lib

export DIST_PHP_VER=5.6.11

pushd ${OPENSHIFT_REPO_DIR}/misc

chmod +x make_php
echo 'before source make_php'
source make_php
echo 'before check_all'


The make_php script is:


function install_php() {

function check_php() {
    echo 'entering check php'
    if [[ -x $OPENSHIFT_RUNTIME_DIR/bin/php-cgi ]] ; then
    echo 'entering check php between if'
    if [[ "`$OPENSHIFT_RUNTIME_DIR/bin/php-cgi`" =~ "${DIST_PHP_VER}" ]] ; then
        echo 'leaving check php return 0'
        return 0

    echo "Check PHP ${DIST_PHP_VER} Failed. Start installing"

function check_composer() {

    echo 'entering check composer'
    echo 'leaving check composer'


function check_all() {

    echo 'entering check all'
    echo 'after check php'
    echo 'after composer'


When I execute ./make.sh, the output is:

before source make_php
entering check all
entering check php
entering check php between if

and I don't get the prompt back, I have to CTRL-C

What could be causing this issue? And how to solve it?


When I go to $OPENSHIFT_RUNTIME_DIR/bin/ and execute php-cgi, the program locks... This could explain the issue.

  • I have not written the script myself, so I am not sure what the original developer's intention was. i am not sure what =~ means. I can't find anything with Google. You might be right. Commented Jul 23, 2015 at 20:02
  • @drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it. Commented Jul 23, 2015 at 20:08

1 Answer 1


It looks like the script was running php as an application instead of trying to get the version number. You should be able to fix it by changing the line to read:

if [[ "`$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version`" =~ "${DIST_PHP_VER}" ]] ; then

The =~ test is a regular expression match, part of bash. From the bash(1) man page:

   An  additional  binary operator, =~, is available, with the same prece‐
   dence as == and !=.  When it is used, the string to the  right  of  the
   operator  is  considered  an  extended  regular  expression and matched
   accordingly (as in regex(3)).  The return value  is  0  if  the  string
   matches  the  pattern,  and  1 otherwise.  If the regular expression is
   syntactically incorrect, the conditional expression's return  value  is
   2.   If the shell option nocasematch is enabled, the match is performed
   without regard to the case of alphabetic characters.  Any part  of  the
   pattern  may  be  quoted to force the quoted portion to be matched as a
   string.  Bracket expressions in regular  expressions  must  be  treated
   carefully,  since normal quoting characters lose their meanings between
   brackets.  If the pattern is stored in a shell  variable,  quoting  the
   variable expansion forces the entire pattern to be matched as a string.
   Substrings matched by parenthesized subexpressions within  the  regular
   expression  are  saved in the array variable BASH_REMATCH.  The element
   of BASH_REMATCH with index 0 is the portion of the string matching  the
   entire regular expression.  The element of BASH_REMATCH with index n is
   the portion of the string matching the nth parenthesized subexpression.
  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"? Commented Jul 23, 2015 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .