Autoconf 脚本对带有空格的文件名或路径名有问题。例如,
./configure CPPFLAGS="-I\"/path with space\""
结果(config.log):
configure:3012: gcc -I"/path with space" conftest.c >&5
gcc: with: No such file or directory
gcc: space": No such file or directory
来自 ./configure 的编译命令是ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
,我无法修改它(我也许可以,但以这种方式解决 autoconf 并不是一个通用的解决方案)。
我认为归结为获得一个包含空格的shell变量,以将其解析为单个命令行变量,而不是在空格处拆分。我能想到的最简单的 shell 示例是创建一个带有空格的文件并尝试列出ls
一个 shell 变量作为参数ls
:
$ touch "a b"
$ file="a b"
$ ls $file
ls: a: No such file or directory
ls: b: No such file or directory
这可行,但是是非法的,因为在 autoconf 中我无法修改 shell 代码:
$ ls "$file"
a b
以下引用事物的尝试均无效:
$ file="\"a \"b"; ls $file
ls: "a: No such file or directory
ls: b": No such file or directory
$ file="a\ b"
$ file="a\\ b"
$ file="`echo \\"a b\\"`"
等等。
这是不可能在 shell 脚本中完成的吗?是否有一个神奇的引用可以将带有空格的 shell 变量扩展为单个命令行参数?