Update for compatibility with macOS (BSD grep)

The --max-count option tells grep to stop reading lines after the first matching line. We're looking for the line AFTER the first matching line.
This commit is contained in:
David Cook
2022-09-21 12:22:21 +10:00
parent 086cde83db
commit 96d1616b70

View File

@@ -14,12 +14,12 @@
# Fail if a single command fails.
set -e
# `grep -m 1`: find the first occurrence of "BUNDLED WITH"
# `grep`: find the occurrences of "BUNDLED WITH" (-m is unnecessary and behaves different on macOS)
# `-A`: print the next line after "BUNDLED WITH" as well
# `-x -F`: find exactly that string without interpreting regex
# `tail -n 1`: take the last line, the version line
# `tr -d`: delete all spaces, the indent before the version
version="$(grep -m 1 -A 1 -x -F "BUNDLED WITH" Gemfile.lock | tail -n 1 | tr -d '[:space:]')"
version="$(grep -A 1 -x -F "BUNDLED WITH" Gemfile.lock | tail -n 1 | tr -d '[:space:]')"
# if the length of $version is zero
if [ -z "$version" ]; then