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 using
bashfrom Homebrew 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 standard input. Instead use/dev/stdin.
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"