0

I'm trying to set up a bash function so that I can type a few parameters and create a git pull request:

gpreq "<title>" "<ticketnumber>" "<release>" "<briefdescription>"

I've tried both of these functions to no avail:

gpreq () {
    hub pull-request -m "$1\n\n Ticket: https://ticketsystem.net/issues/$2\n Target Release: $3\n Description: $4" ; }

and also

gpreq() {
    STR="${1}"$'\n\n Ticket: https://ticketsystem.net/issues/'$"${2}"$'\n Target Release: '$"${3}"$'\n Description: '$"${4}"
    hub pull-request -m "${STR}" ;
}

For some reason the line breaks don't seem to be working, instead the \n is coming through as actual characters. Any help would be appreciated!

3
  • What version is your bash (bash --version)? I have bash 4.3 and it handles the ANSI-C quoting perfectly. Commented Jun 6, 2018 at 18:44
  • Hmm, ANSI-C quoting was added to bash in verion 2.0 -- surely your bash version is more recent than that. (git.savannah.gnu.org/cgit/bash.git/tree/NEWS?h=bash-4.4#n1754) Commented Jun 6, 2018 at 18:45
  • I'm using the Bash that comes with the Windows download of Git (git-scm.com) - says it's 4.4.19. Commented Jun 6, 2018 at 18:56

1 Answer 1

1

(I don't know what hub is)

\n is a character that is converted by some command as a newline.

try inserting directly newlines

hub pull-request -m "$1

 Ticket: https://ticketsystem.net/issues/$2
 Target Release: $3
 Description: $4"

or use some function that interpred \n:

STR="$1\n\n Ticket: https://ticketsystem.net/issues/$2\n Target Release: $3\n Description: $4"
STR
hub pull-request -m "`printf "${STR}"`"
Sign up to request clarification or add additional context in comments.

2 Comments

printf ${STR} leaves the variable unquoted, and it will destroy the whitespace formatting. Also, have to beware that the string may contain % characters with will cause printf errors. I don't recommend using printf without an explicit format string.
Worked great! FYI, hub is a wrapper for git for use on GitHub (github.com/github/hub).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.