当我执行下面的脚本时,它会报告一个错误,但是如果我手动执行echo的命令,我不会报告一个错误,它们显然是一样的!
我试着在Linux, Windows上执行这个脚本,他们都报告相同的错误。虽然Linux上没有命令MinGW Makefiles
,但是即使有,它也会被报告。因为错误提示是Could not create named generator "MinGW
而不是Could not create named generator "MinGW Makefiles"
如何解决这个问题?
#!/bin/bash
compiler_options=(' -G "MinGW Makefiles"')
echo "cmake -S . -B build ${compiler_options}"
cmake -S . -B build ${compiler_options}
# run command
bash test.sh
# errorinfo
CMake Error: Could not create named generator "MinGW
使用数组的目的是避免将所有参数塞进一个以空格分隔的字符串中。
#!/bin/bash
compiler_options=(-G "MinGW Makefiles")
echo "cmake -S . -B build ${compiler_options[*]}"
cmake -S . -B build "${compiler_options[@]}"