Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

bash - xcodebuild command in shell script iOS

I have a complete command to deploy the xCode project on real device.

i.e

xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug -destination 'platform=iOS,name=Shujaat’s iPad' clean test

its working fine using the command line.

Todo: I wanted to execute this command via a shell script.

here is my complete shell script deploy.sh so for.

#!/bin/bash
#My First Script

#Info to be configured 


current_path=$(pwd)
appName="jamesApp"
jamesApp_workspace="jamesAppV2.xcworkspace"

echo "Searching for $jamesApp_workspace workspace..."

if [[ $(ls $jamesApp_workspace) ]];     then 
    echo "$jamesApp_workspace found in current directory."


echo "Listing all installed and connected devices..."
instruments -s devices

echo "Copy + Paste from above devices"
echo "specify name of your decice to launch $appName"
read d_device_name

echo "building workspace for $d_device_name..."

build_cmd=(xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug)
destination="'platform=iOS,name=$d_device_name'"

build_cmd+=(-destination "$destination" clean test)

echo "${build_cmd[@]}"
# Here it prints the valid command given above

"${build_cmd[@]}"

else
    echo "$jamesApp_workspace workspace not found"
    echo "Make sure your current path contains the $jamesApp_workspace workspace"
    echo "Place this file i.e deploy.sh within the directory containing $jamesApp_workspace workspace"
fi;

Problem: I have done like

build_cmd=(xcodebuild -workspace jamesAppV2.xcworkspace -scheme jamesAppV2 -configuration Debug)
destination="'platform=iOS,name=$d_device_name'" 
build_cmd+=(-destination "$destination" clean test) 
echo "${build_cmd[@]}"  #Prints valid command
"${build_cmd[@]}" 

but gives error on execution

xcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'

if I run the above command via command line its working perfectly but If I run this via shell script its not working.

I have referred I want to concatenate arguments of xcodebuild as string, which have space in it ,then run this command to concatenate the xcodebuild command

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The shell removes the single quotes in the original command, therefore you should not have any when creating the array either.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...