1

I often use git commit -F- <<EOF in order to write an EOF-terminated string as a commit message.

Using

alias commitml="git commit -F- <<EOF"

Works as intended.

However I would like to be able to pass arguments.

So I wanted to define in my .bashrc:

commitml() {
   git commit $* -F- <<EOF
}

Which returns as an error when source()ing:

bash: warning: here-document at line 6 delimited by end-of-file (wanted `EOF') bash: /home/yannick/.bashrc: line 8: syntax error: unexpected end of file

Is it possible to somewhat escape the << so that it works just like in the alias?

3

The EOF is evaluated when the function is defined; of course Bash is skipping the rest of the script until it finds the matching EOF terminator.

What you seem to be looking for is a way to consume standard input up through a particular token. The usual way to do that is to simply type your message and end it with a ctrl-D (or whatever your terminal is set up to use for signalling end of file).

commitml() {
   git commit "$@" -F-
}

You could use this like commitml <<EOF if you like, of course; or perhaps rename the function to _commitml and set

alias commitml='_commitml <<EOF'

This is one of the few valid uses of an alias over a function -- the text inside the single quotes only gets evaluated when you actually use the alias. Any tokens after commitml will get passed into "$@" (notice also the use of this properly quoted variable over the quoting-buggy $*).

Your Answer

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