A Bundle identifier in Info.plist of an Xcode project could have various forms, for e.g.

1. com.company.$(PRODUCT\_NAME:rfc1034identifier)
2. $(PRODUCT\_BUNDLE\_IDENTIFIER)
3. Someone could design their own product bundle identifier for debug, release etc types of build and write a variable against Bundle identifier, e.g. com.company.$(PRODUCT\_NAME:rfc1034identifier).$(someRandomVariable)

I want to write a shell script that just reads the bundle identifier properly. 

However, if you only know shell script - I know, how to figure out values of variables in $(), but want a shell script that should give me all such variables in the string and then I will have code to figure out their values, post which I will create string back with the variables replaced with values.

```
function getBundleIdentifier
{
    cfBundleIdentifier=${PRODUCT_BUNDLE_IDENTIFIER}
    if [ ${#cfBundleIdentifier} -lt 1 ]; then

        SOURCE="rfc1034identifier"
        cfBundleIdentifier=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "${PROJECT_DIR}/${INFOPLIST_FILE}")

        if echo "$cfBundleIdentifier" | grep -q "$SOURCE"; then
            echo `eval echo $cfBundleIdentifier``eval echo ${PRODUCT_NAME:rfc1034identifier}`
        else
            echo `eval echo $cfBundleIdentifier`
        fi

    else
        echo $cfBundleIdentifier
   fi
}

```

This is what I have written, but it does not cover all the cases.