I am creating a bash script to setup a development environment. As part of my script I need to install Xcode Command Line Tools and I don't want the script to continue execution until the installation has been completed.
When I run:
xcode-select --install
It prints that an install has been requested or that it has already been installed. I want to be able to wait until the message changes to already being installed.
The relevant part of my script is as follows:
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
Unfortunately $check
is always empty because xcode-select --install
does not return anything and instead echoes the message to the terminal.
I know you have probably already solved this issue, I had a crack at this problem today, and discovered that it prints to stderr and not stdout. This is the code I used to determine whether Xcode is installed or not:
check=$((xcode-\select --install) 2>&1)
echo $check
str="xcode-select: note: install requested for command line developer tools"
while [[ "$check" == "$str" ]];
do
osascript -e 'tell app "System Events" to display dialog "xcode command-line tools missing." buttons "OK" default button 1 with title "xcode command-line tools"'
exit;
done
Hope this helps someone in the future :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With