V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
mreasonyang
V2EX  ›  Linux

请问如何正确使用 shell 变量作为 Linux 编译安装程序时 configure 的选项参数

  •  
  •   mreasonyang ·
    MrEasonYang · 2016-07-14 23:25:19 +08:00 · 2650 次点击
    这是一个创建于 2813 天前的主题,其中的信息可能已经有所发展或是发生改变。

    正在写一个小脚本,需要从配置文件里读取 configure 参数然后编译安装 nginx ,代码如下。 ./configure $configure_parameters
    make && make install

    configure 的选项大致为: --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules/ --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'

    现在遇到的问题是无法处理带着单引号的 --with-cc-opt ,不加双引号报非法参数 -g ,加双引号则会获取不到正确的参数,显示为: ...... nginx path prefix: "/etc/nginx/ --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules/ --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' ...... 这样类似的配置结果,进而无法正确 make 。

    请问各位有什么解决的办法呢?我对 Shell 也是刚入门,希望大家指导下。谢谢大家。

    2 条回复    2016-07-16 12:42:28 +08:00
    AntonChen
        1
    AntonChen  
       2016-07-14 23:32:09 +08:00 via iPhone
    转义?
    mreasonyang
        2
    mreasonyang  
    OP
       2016-07-16 12:42:28 +08:00
    @AntonChen 仍然不行诶
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3310 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:20 · PVG 21:20 · LAX 06:20 · JFK 09:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.