在bash脚本生成错误中运行命令。

时间:2021-01-05 00:25:40

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.

我正在尝试编写一个bash脚本,它封装了phpbrew开关,这样我就可以同时切换apache模块。一切正常,只是phpbrew交换机php-7.0.01不能正常运行。

code ($version being fed by input)

代码($版本由输入提供)

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

error

错误

Invalid argument php-7.0.1

无效的论点php-7.0.1

running phpbrew switch php-7.0.1 executes with no errors.

运行phpbrew交换机php-7.0.1无错误执行。

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

phpbrew有什么奇怪的进展吗?还是我想在巴什做些傻事?

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

/ switchphp。上海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

马特/home/matt/.phpbrew/php/php-7.0.1/bin:/ home / / .phpbrew / bin:/ usr /地方/ sbin:/ usr /地方/ bin:/ usr / sbin:/ usr / bin:/ sbin:/ bin:/ usr /游戏:/ usr /地方/游戏

1 个解决方案

#1


3  

ok, so managed to get an answer on github

好吧,所以找到了关于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.

在bash文件中的命令调用之前。显然,在脚本中没有从我的主目录中拖出bashrc。

#1


3  

ok, so managed to get an answer on github

好吧,所以找到了关于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.

在bash文件中的命令调用之前。显然,在脚本中没有从我的主目录中拖出bashrc。