关于解决shell脚本中无法用cd命令,在指定文件下运行指定文件的解决方法分享

本人以编写shell脚本,一键安装配置php7.3为例

前提:本脚本在Linux  /opt/目录下运行

首先解压php压缩包

######  配置nginx,带lua支持    #################################################
tar -zxvf /opt/php-7.3.30.tar.gz
if [ $? -eq 0 ];then
    echo `date "+%y-%m-%d %H:%M:%S"` "\nphp解压成功" | tee -a /opt/wnote_install.log
else
    echo `date "+%y-%m-%d %H:%M:%S"` "\nphp解压失败" | tee -a /opt/wnote_install.log
    exit 1
fi

配置php安装路径和模块

当时用以下语句运行configure时,发现cd命令实际上是没有用的,程序并没有切换到/opt/php-7.3.30/目录下执行configure,运行脚本时出现错误,无法按照configure的参数进行配置

cd /opt/php-7.3.30/
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts

使用下列命令也不可以

/opt/php-7.3.30/configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts

查阅网友的经验,发现某网友提供的代码中,在cd命令后面的路径名加上了双引号,经测试成功运行,如下列代码所示,但是本人并没有在网络上查找到cd命令的这种用法解释,本人网络小白一个并未能分析出原因,欢迎各位网友在评论区给出权威解答

#配置php安装路径和模块、进行编译和安装▲
cd "/opt/php-7.3.30/"  #切换到该目录下执行下一条命令
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts
if [ $? -eq 0 ];then
    echo `date "+%y-%m-%d %H:%M:%S"` "\nphp安装路径和模块配置成功" | tee -a /opt/wnote_install.log
else
    echo `date "+%y-%m-%d %H:%M:%S"` "\nphp安装路径和模块配置失败,请检查故障" | tee -a /opt/wnote_install.log
    exit 1
fi
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值