ionCube shell 脚本给出错误

ionCube shell 脚本给出错误

我有这个 shell 脚本来安装 ionCube 加载程序:

if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
echo "Welcome to this script to install the ionCube loader on CentOS!"
cd /usr/local/src
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar zxvf ioncube_loaders_lin_x86-64.tar.gz
cd  ioncube
mkdir /usr/local/ioncube
echo "Please specify which PHP version you are using (e.g.: 5.3)."
read version
cp ioncube_loader_lin_"$version".so /usr/local/ioncube
path=$(php -i|grep php.ini | awk 'NR==2{print $5}')
read path
echo "zend_extension = /usr/local/ioncube/ioncube_loader_lin_"$version".so" >> "$path"

CentOS 6.5 Final当我尝试使用此 PHP 版本 ( )运行它时php -v

PHP 5.3.28 (cli) (built: Jun 23 2014 16:25:09) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

我收到以下错误:

./ioncube.sh: line 17: : File or folder doesn't exist

17号线:

echo "zend_extension = /usr/local/ioncube/ioncube_loader_lin_"$version".so" >> "$path"

该错误表明该内容$path不存在。当我尝试手动运行$path( )命令时php -i|grep php.ini | awk 'NR==2{print $5}',输出为:

/usr/local/lib/php.ini

当我尝试运行第 17 行但替换$path为命令的实际输出时(当然我也会替换$version):

echo "zend_extension = /usr/local/ioncube/ioncube_loader_lin_"5.3".so" >> "/usr/local/lib/php.ini"

命令成功。

我不明白这里出了什么问题。

答案1

问题是read path.当一行创建$path变量时,下一行再次将其设置为空白:

## This line will set the $path variable.
path=$(php -i|grep php.ini | awk 'NR==2{print $5}')
## This one expects to read the value of $path from standard input 
## so it sets it to empty unless input is given.
read path

您可以通过echo "$path"在第 17 行之后以及read path.您会看到第二个打印一个空字符串。您还可以在错误消息中看到这就是问题所在:

./ioncube.sh: line 17: : File or folder doesn't exist
                     ---
                      |---------> this should be the file name

因此,只需删除该read path行即可。

相关内容