[英]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. 我试图写一个包装
phpbrew switch
的bash脚本,以便我可以同时切换apache模块。 Everything is working, except that I can't get the phpbrew switch php-7.0.01
to run properly. 一切正常,除了我无法使
phpbrew switch php-7.0.01
正常运行。
code ( $version
being fed by input) 代码 (
$version
由输入提供)
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 switch php-7.0.1
可以正确执行。
Is there something odd going on with phpbrew? phpbrew有什么奇怪的事情吗? or am I trying to do something silly in bash?
还是我想在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
./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: $ PATH输出:
/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/matt/.phpbrew/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/斌:/ sbin目录:/ bin中:在/ usr /游戏:在/ usr /本地/游戏
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. 在bash文件中的命令调用之前。 Clearly wasnt pulling the bashrc from my home dir while in the script.
在脚本中时,显然并没有从我的主目录中拉出bashrc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.