1
我正在掙扎成一個奇怪的問題。我試圖運行一個shell變量作爲參數的cmake命令行,但它失敗。這是我做了什麼:用bash變量參數調用cmake
#1. Basic. works fine
cmake -G 'Sublime Text 2 - Ninja'
#2. Argument into variable. error
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake $CMAKE_CONFIG ../..
> CMake Error: Could not create named generator 'Sublime Text 2 - Ninja'
#3. Adding -v before variable. 'compile' but ignore the argument (generate a Makefile). Hacky and senseless?
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake -v$CMAKE_CONFIG ../..
#4. Quoting argument. error (same as #2)
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake "$CMAKE_CONFIG" ../..
與--trace和--debug輸出變量的播放提供了以下:
#5. Working command
cmake ../.. --trace --debug-output -G "Sublime Text 2 - Ninja"
#6. Non existing generator.
#Expected result (witness purpose only)
cmake ../.. --trace --debug-output -G 'random test'
[...]
CMake Error: Could not create named generator random test
#7. Testing with variable.
#Output error quotes the generator's name and there is an extra space before it
cmake ../.. --trace --debug-output $CMAKE_CONFIG
[...]
CMake Error: Could not create named generator 'Sublime Text 2 - Ninja'
#8. Removing the quote within the variable.
#Still error, but the only difference with #6 is the extra space after 'generator'
CMAKE_CONFIG="-G Sublime Text 2 - Ninja"
cmake ../.. --trace --debug-output $CMAKE_CONFIG
[...]
CMake Error: Could not create named generator Sublime Text 2 - Ninja
我試圖改變IFS變量太多,但沒成功實現我的目標。
任何提示?
正確的。參見[BashFAQ#50:我試圖將一個命令放入一個變量中,但複雜的情況總是失敗!](http://mywiki.wooledge.org/BashFAQ/050)以獲取更多詳細信息。 –