2
我正在創建一個bash腳本來設置開發環境。作爲我的腳本的一部分,我需要安裝Xcode命令行工具,並且我不希望腳本在安裝完成之前繼續執行。驗證Xcode命令行工具安裝在Bash腳本中
當我運行:
xcode-select --install
它打印,如果要安裝已請求或者它已經安裝。我希望能夠等到消息更改爲已安裝。
我的劇本的相關部分如下:
check="$(xcode-\select --install)"
echo "$check"
str="xcode-select: note: install requested for command line developer tools\n"
while [[ "$check" == "$str" ]];
do
check="$(xcode-\select --install)"
sleep 1
done
不幸$check
永遠是空的,因爲xcode-select --install
不返回任何東西,而是相呼應的消息發送到終端。
難道輸出該消息到標準錯誤? 'xcode-select --install 2>&1'有幫助嗎? –
在_「...我的腳本的相關部分...」中,您有'check =「$(xcode- \ select --install)」',不應該是'check =「$(xcode-選擇--install)「'?換句話說,'xcode-select'中的'-'和's'之間沒有_backslash_。 – user3439894
沒有斜槓我在我的腳本的其餘部分有錯誤,因爲'select'是bash中的保留字 –