我有一个完整的命令来在真实设备上部署 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/