shell 脚本 iOS 中的 xcodebuild 命令

xcodebuild command in shell script iOS

我有在真实设备上部署 xCode 项目的完整命令。

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

使用命令行运行良好。

待办事项: 我想通过 shell 脚本执行此命令。

这是我的完整 shell 脚本 deploy.sh 因此。

#!/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;

问题: 我做过

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[@]}" 

但执行时出错

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

如果我 运行 通过命令行执行上述命令,则它可以正常工作,但是如果我 运行 通过 shell 脚本执行此命令,则无法正常工作。

我已经提到 I want to concatenate arguments of xcodebuild as string, which have space in it ,then run this command 连接 xcodebuild 命令

shell 删除了原始命令中的单引号,因此您在创建数组时也不应该有任何单引号。

我也试图通过字符串传递以类似的方式执行命令。该命令对我来说在命令的任何地方都没有双引号。

示例:

$ xcodebuild -project ~/ios_projects/example.xcodeproj -scheme Xcode9-XCtest destination id=EBCDFH7S-DCJD-EE8D-DSKDKD78