4

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.

4
  • Is it outputting that message to standard error? Does xcode-select --install 2>&1 help? Commented May 29, 2015 at 15:52
  • In the "... relevant part of my script ..." you have check="$(xcode-\select --install)", shouldn't that be check="$(xcode-select --install)"? in other words, no backslash between the - and s in xcode-select. Commented May 29, 2015 at 16:03
  • Without the slash I got errors in the rest of my script because select is a reserved word in bash Commented May 29, 2015 at 16:30
  • Interesting, I'm using OS X too and it does not throw an error for me without the backslash, in a script or from the command line. Commented May 29, 2015 at 17:17

1 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.