Modify PRODUCT_BUNDLE_IDENTIFIER in project.pbxpro

2019-02-25 02:57发布

问题:

I'm trying to modify the project.pbxproj file of Xcode project using sed shell command on Mac Terminal to replace a string. I want to replace the field -

PRODUCT_BUNDLE_IDENTIFIER = com.example.71b9b4f2

to

PRODUCT_BUNDLE_IDENTIFIER = com.example.14a32d1e

Command used -

sed -i 's/com.example.71b94f2/com.example.14a32d1e/g' project.pbxproj

which produces the following output error-

sed: 1: "project.pbxproj": extra characters at the end of p command

I was earlier using Plistbuddy shell command to modify the field CFBUNDLEIDENTIFIER in info.plist but that doesn't change $(PRODUCT_BUNDLE_IDENTIFIER) in Xcode 7 build settings anymore.

My main aim is to modify the PRODUCT_BUNDLE_IDENTIFIER field of BUILD SETTINGS in Xcode using command line or any script.

回答1:

OSX requires the extension to be explicitly specified. The workaround is to set an empty string:

sed -i '' 's/com.example.71b94f2/com.example.14a32d1e/g' project.pbxproj