Having a hard time passing a "greater than or equal to" value in my if-then-else statement with a decimal integer ran as a one-liner and curling the phpinfo.php page to check if the domain's PHP version is greater than or equal to 7.0. Obviously a php info file (phpinfo.php) is created in the main dir of where site is assigned. Here is my command displayed in human readable:
read -ep "Enter the domain: " DOMAIN ;
PHPVERSION=$(curl -s https://$DOMAIN/phpinfo.php | grep -ioP 'php version\s\K\d.\d') ;
if [ $PHPVERSION >= 7.0 ] ;
then
echo -e "PHP version at least 7.0? YES" ;
else
echo -e "PHP version at least 7.0? NO\nPHP version = $PHPVERSION" ;
fi ;
[~]# echo $PHPVERSION
7.0
Here are the tests/outputs I use/get when attempting to run the command
if [ $PHPVERSION >= 7.0 ]
-jailshell: [: 7.0: unary operator expected
PHP version at least 7.0? NO
PHP version = 7.0
if [ $PHPVERSION -ge 7.0 ]
-jailshell: [: 7.0: integer expression expected
PHP version at least 7.0? NO
PHP version = 7.0
if [[ $PHPVERSION >= 7.0 ]]
-jailshell: syntax error in conditional expression
-jailshell: syntax error near `7.0'
if [[ $PHPVERSION -ge 7.0 ]]
-jailshell: [[: 7.0: syntax error: invalid arithmetic operator (error token is ".0")
PHP version at least 7.0? NO
PHP version = 7.0
I can get it to work just fine as >
or -gt
but the PHP version I'm requiring for my test is greater than or equal to 7.0. What am I missing here? I've also tried passing 7.0 as a variable and testing it that way but get the same output on virtually all my tests. I've also tried saving 7.0 as a variable using echo and piping it into bc
but I don't think I'm doing it right. Also double quotes around variable don't seem to help either. I feel like this is something simple but I've definitely looked around at all articles I could find on the subject and have yet to come up with anything that works. Thanks for the help.
Aucun commentaire:
Enregistrer un commentaire