When I execute the following script, it will report an error, but if I manually execute the command of the echo, I will not report an error, they are clearly the same!
I tried to execute this script in Linux, Windows, they all report the same error. Although there is no command MinGW Makefiles
on Linux, it will appreciate that even if there is, it will be reported. Because the error prompt is Could not create named generator "MinGW
instead of Could not create named generator "MinGW Makefiles"
How can I fix this problem?
#!/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
CodePudding user response:
The point of using an array is to avoid cramming all the arguments into a single whitespace-delimited string.
#!/bin/bash
compiler_options=(-G "MinGW Makefiles")
echo "cmake -S . -B build ${compiler_options[*]}"
cmake -S . -B build "${compiler_options[@]}"