ios - shell 脚本 iOS 中的 xcodebuild 命令

标签 ios bash shell command-line xcodebuild

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

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

使用命令行工作正常。

Todo: 我想通过 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 删除了原始命令中的单引号,因此在创建数组时也不应该有任何单引号。

关于ios - shell 脚本 iOS 中的 xcodebuild 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37042815/

相关文章:

spring - 我在运行以交互模式打开 docker 容器并执行一些命令的 bash 脚本时遇到问题

java - 如何将显示传递给 qsub 命令?

shell - 为什么 find 在传递当前目录与路径时返回不同的排序结果?

ios - 更新pod内部库

objective-c - 在 prepareForSegue 中传递对 ViewController 的引用

ios - 无法用字典中的数字替换对象

bash - 定界间距?

python - 终端中的嵌套 For 循环

linux - 如何使用 set 更改 shell 变量?

ios - 定位到哪个版本的iPhone/iPod Touch