Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...