Pat*_*ick 14 bash shell autoconf
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变量扩展为单个命令行参数?
您应该尝试设置$IFS环境变量.
来自man bash(1):
IFS - 内部字段分隔符,用于在扩展后进行单词拆分,并使用read builtin命令将行拆分为单词.默认值为''space tab newline''.
例如
IFS=<C-v C-m>  # newline
file="a b"
touch $file
ls $file
不要忘记$IFS挫折或奇怪的事情会发生.