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

2016-07-14 23:25:19 +08:00
 mreasonyang

正在写一个小脚本,需要从配置文件里读取 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 也是刚入门,希望大家指导下。谢谢大家。

2660 次点击
所在节点    Linux
2 条回复
AntonChen
2016-07-14 23:32:09 +08:00
转义?
mreasonyang
2016-07-16 12:42:28 +08:00
@AntonChen 仍然不行诶

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/292591

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX