Skip to main content
added 49 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash shell from the Homebrew package manager (or equivalent), or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also can't use - as the option-argument to -f to mean "read from standard inputinput". Instead use Use /dev/stdin instead.

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

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash from Homebrew or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also 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

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

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 installing a newer bash shell from the Homebrew package manager (or equivalent), or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also can't use - as the option-argument to -f to mean "read from standard input". Use /dev/stdin instead.

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
added 311 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash from Homebrew or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also 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}$PODS_PODFILE_DIR_PATH/Podfile"Podfile <<'END'
s/^ *pod ['"]XXX["'],.*:commit *=> *["']([^'"]*)["'].*$/\1/p
END
)

echo "$hash_in_podfile"$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

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash from Homebrew or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also 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"

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash from Homebrew or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also 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

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
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

There are two issues in your script:

  1. The sh on macOS is a very old version of the bash shell, 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 bash from Homebrew or by using the zsh shell on macOS.

  2. The sed on macOS does not have an -r option. To use extended regular expressions with sed on macOS, use -E (this is also supported by GNU sed nowadays). Your expression does not use extended regular expression features though, so just removing the option would be ok too. macOS sed also 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"