Cannot get the latest item from a range in bash

I’m trying to ‘git diff’ last commit PR in GH but the commit does not seem to be the correct one. So used the following:

echo "commit range: ${TRAVIS_COMMIT_RANGE}"

and I got:

commit range: 76acf3b3b213cd3f4f1e3a023e250ca23072fedd...474b7552e8a605b860df7b353dc8658d5025b0bf

So now I need to parse the above range to get only string like:

474b7552e8a605b860df7b353dc8658d5025b0bf

But when I do this in bash:

echo "commit range: ${TRAVIS_COMMIT_RANGE[-1]}"

I get:

: bad array subscript
$TRAVIS_COMMIT_RANGE 

This isn’t an array, it’s a single string. Try a parameter expansion instead:

${TRAVIS_COMMIT_RANGE##*.}  # Remove all code until final character (the period) 
1 Like

This did it! thank you.

Hey @SolarUltima,

If you need anything else do not hesitate to post back!