简体   繁体   中英

running command in bash script producing error

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM