I'm trying to parse out the last number of this url in bash function 1 and pass that result into bash function 2.

I have this elementary example I have been playing with:

  1 pullpr() {
  2         git checkout pr/$1
  3 }
  5 co() {
  6         pullpr awk -F/ '{print $7}' <<<$1
  7 }

I can't seem to get this to work, but I'm wanting to do this correct way.


You can use the shell’s parameter expansion features to extract the number:

echo "${url##*/}"

This will also work with positional parameters:

set https://github.com/org/repo/pull/777
echo "${1##*/}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.