There are two issues in your script:
The
shon macOS is a very old version of thebashshell, and it has a bug that stops you from using unbalanced quotes in here-documents in command substitutions:$ a=$( cat <<'END' > " > END > ) > sh: unexpected EOF while looking for matching `"'(I had to press Ctrl+D after the
)at the end there.)You can get by this by usinginstalling a newer
bashshell from the Homebrew package manager (or equivalent), or by using thezshshell on macOS.The
sedon macOS does not have an-roption. To use extended regular expressions withsedon macOS, use-E(this is also supported by GNUsednowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOSsedalso can't use-as the option-argument to-fto mean "read from standard inputinput". Instead use Use/dev/stdininstead.
Suggestion:
#!/bin/zsh
PODS_PODFILE_DIR_PATH='/Users/path/to/file'
# just a comment
hash_in_podfile=$(sed -n -f /dev/stdin -- $PODS_PODFILE_DIR_PATH/Podfile <<'END'
s/^ *pod ['"]XXX["'],.*:commit *=> *["']([^'"]*)["'].*$/\1/p
END
)
echo $hash_in_podfile
If all you want to do is to output the value, then don't use an intermediate variable:
#!/bin/zsh
PODS_PODFILE_DIR_PATH='/Users/path/to/file'
# just a comment
sed -n -f /dev/stdin -- $PODS_PODFILE_DIR_PATH/Podfile <<'END'
s/^ *pod ['"]XXX["'],.*:commit *=> *["']([^'"]*)["'].*$/\1/p
END