bash script locked at if statement when executed

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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:



#!/bin/bash

export OPENSHIFT_RUNTIME_DIR=$OPENSHIFT_HOMEDIR/app-root/runtime
export ROOT_DIR=$OPENSHIFT_RUNTIME_DIR #CARTRIDGE
export LIB_DIR=$ROOT_DIR/lib
export CONF_DIR=$OPENSHIFT_REPO_DIR/conf

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'
check_all

popd


The make_php script is:



#!/bin/bash

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
fi
fi

echo "Check PHP $DIST_PHP_VER Failed. Start installing"
install_php


function check_composer()

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



function check_all()

echo 'entering check all'
check_php
echo 'after check php'
check_composer
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?



UPDATE



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










share|improve this question



















  • 1





    Did you mean to run php-cgi --version?

    – drewbenn
    Jul 23 '15 at 20:01











  • 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.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:02












  • @drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:08

















0















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:



#!/bin/bash

export OPENSHIFT_RUNTIME_DIR=$OPENSHIFT_HOMEDIR/app-root/runtime
export ROOT_DIR=$OPENSHIFT_RUNTIME_DIR #CARTRIDGE
export LIB_DIR=$ROOT_DIR/lib
export CONF_DIR=$OPENSHIFT_REPO_DIR/conf

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'
check_all

popd


The make_php script is:



#!/bin/bash

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
fi
fi

echo "Check PHP $DIST_PHP_VER Failed. Start installing"
install_php


function check_composer()

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



function check_all()

echo 'entering check all'
check_php
echo 'after check php'
check_composer
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?



UPDATE



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










share|improve this question



















  • 1





    Did you mean to run php-cgi --version?

    – drewbenn
    Jul 23 '15 at 20:01











  • 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.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:02












  • @drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:08













0












0








0








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:



#!/bin/bash

export OPENSHIFT_RUNTIME_DIR=$OPENSHIFT_HOMEDIR/app-root/runtime
export ROOT_DIR=$OPENSHIFT_RUNTIME_DIR #CARTRIDGE
export LIB_DIR=$ROOT_DIR/lib
export CONF_DIR=$OPENSHIFT_REPO_DIR/conf

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'
check_all

popd


The make_php script is:



#!/bin/bash

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
fi
fi

echo "Check PHP $DIST_PHP_VER Failed. Start installing"
install_php


function check_composer()

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



function check_all()

echo 'entering check all'
check_php
echo 'after check php'
check_composer
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?



UPDATE



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










share|improve this question
















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:



#!/bin/bash

export OPENSHIFT_RUNTIME_DIR=$OPENSHIFT_HOMEDIR/app-root/runtime
export ROOT_DIR=$OPENSHIFT_RUNTIME_DIR #CARTRIDGE
export LIB_DIR=$ROOT_DIR/lib
export CONF_DIR=$OPENSHIFT_REPO_DIR/conf

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'
check_all

popd


The make_php script is:



#!/bin/bash

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
fi
fi

echo "Check PHP $DIST_PHP_VER Failed. Start installing"
install_php


function check_composer()

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



function check_all()

echo 'entering check all'
check_php
echo 'after check php'
check_composer
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?



UPDATE



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







bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 3:19









Rui F Ribeiro

42.1k1484142




42.1k1484142










asked Jul 23 '15 at 19:37









Jérôme VerstryngeJérôme Verstrynge

59441019




59441019







  • 1





    Did you mean to run php-cgi --version?

    – drewbenn
    Jul 23 '15 at 20:01











  • 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.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:02












  • @drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:08












  • 1





    Did you mean to run php-cgi --version?

    – drewbenn
    Jul 23 '15 at 20:01











  • 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.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:02












  • @drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

    – Jérôme Verstrynge
    Jul 23 '15 at 20:08







1




1





Did you mean to run php-cgi --version?

– drewbenn
Jul 23 '15 at 20:01





Did you mean to run php-cgi --version?

– drewbenn
Jul 23 '15 at 20:01













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.

– Jérôme Verstrynge
Jul 23 '15 at 20:02






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.

– Jérôme Verstrynge
Jul 23 '15 at 20:02














@drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

– Jérôme Verstrynge
Jul 23 '15 at 20:08





@drewbenn I have just added --version and the issue is gone. Thanks. If you create the answer, I'll approve it.

– Jérôme Verstrynge
Jul 23 '15 at 20:08










1 Answer
1






active

oldest

votes


















2














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.





share|improve this answer

























  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

    – Jérôme Verstrynge
    Jul 23 '15 at 20:21











  • yeah.. I did :(

    – drewbenn
    Jul 23 '15 at 20:23











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f217960%2fbash-script-locked-at-if-statement-when-executed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














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.





share|improve this answer

























  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

    – Jérôme Verstrynge
    Jul 23 '15 at 20:21











  • yeah.. I did :(

    – drewbenn
    Jul 23 '15 at 20:23















2














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.





share|improve this answer

























  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

    – Jérôme Verstrynge
    Jul 23 '15 at 20:21











  • yeah.. I did :(

    – drewbenn
    Jul 23 '15 at 20:23













2












2








2







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.





share|improve this answer















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.






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 23 '15 at 20:22

























answered Jul 23 '15 at 20:18









drewbenndrewbenn

5,38451936




5,38451936












  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

    – Jérôme Verstrynge
    Jul 23 '15 at 20:21











  • yeah.. I did :(

    – drewbenn
    Jul 23 '15 at 20:23

















  • You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

    – Jérôme Verstrynge
    Jul 23 '15 at 20:21











  • yeah.. I did :(

    – drewbenn
    Jul 23 '15 at 20:23
















You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

– Jérôme Verstrynge
Jul 23 '15 at 20:21





You mean "$OPENSHIFT_RUNTIME_DIR/bin/php-cgi --version"?

– Jérôme Verstrynge
Jul 23 '15 at 20:21













yeah.. I did :(

– drewbenn
Jul 23 '15 at 20:23





yeah.. I did :(

– drewbenn
Jul 23 '15 at 20:23

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f217960%2fbash-script-locked-at-if-statement-when-executed%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?