2
votes

problem

Im trying to write a bash script that wraps phpbrew switch so that I can switch the apache module at the same time. Everything is working, except that I can't get the phpbrew switch php-7.0.01 to run properly.

code ($version being fed by input)

if [ -v version ]; then
        phpbrew switch php-$version
fi

error

Invalid argument php-7.0.1

running phpbrew switch php-7.0.1 executes with no errors.

Is there something odd going on with phpbrew? or am I trying to do something silly in bash?

full script

#!/bin/bash
# wraps phpbrew switch to enable apache switching

module_path=/usr/lib/apache2/modules
if [ $1 ]; then
        echo "switching php to version ${1}..."
        if [ $1 = "5.6.4" ]; then
                set=5
                version=5.6.4
                so_path=libphp5.6.4.so
        fi
        if [ $1 = "5.6.15" ]; then
                set=5
                version=5.6.15
                so_path=libphp5.6.15.so
        fi
        if [ $1 = "7.1" ]; then
                set=7
                version=7.0.1
                so_path=libphp7.1.0-dev.so
        fi
fi
echo "version selected = ${version}"

if [ -v version ]; then
        phpbrew switch php-$version

        echo "" > /etc/apache2/mods-available/php7.load
        echo "" > /etc/apache2/mods-available/php5.load
        echo "LoadModule php${set}_module $module_path/${so_path}" > /etc/apache2/mods-available/php${set}.load
        service apache2 restart
else
        echo "no version set"
fi

entry into terminal

./switchphp.sh 7.1

full output

switching php to version 7.1
version selected = 7.0.1 
Invalid argument php-7.0.1

extra info

$PATH output:

/home/matt/.phpbrew/php/php-7.0.1/bin:/home/matt/.phpbrew/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

1
Please post something that can be reproduced, i.e., assign some value to version please (you could very well have some trailing spaces in version, which may not be immediately recognizable in error messages). - 4ae1e1
Could you maybe add the full script and an example of how you call it to produce that error? - madsen
updated. thanks for looking. its been driving me nuts - DevDonkey
What does your full output look like? - miken32
How is the version variable populated? From a file that has \r\n line endings perhaps? - glenn jackman

1 Answers

4
votes

ok, so managed to get an answer on github

all I needed to do was put

source $HOME/.phpbrew/bashrc
phpbrew switch php-${version}

before the command call in the bash file. Clearly wasnt pulling the bashrc from my home dir while in the script.