Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to get some nice output out of git:

FORMAT='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
LOG_PARAMS="--color --pretty=format:$FORMAT --abbrev-commit --no-walk"
function gch() {
  git log $LOG_PARAMS $(commits)
}

(where commits is a function that collects relevant commits). But I get this instead:

fatal: ambiguous argument '%(s)': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

Presumably that has something to do with the quoting and spaces, but I'm far from fluent in bash. Any help?

share|improve this question
    
The function prefix is a bashism, and can be removed without changing anything. –  l0b0 Sep 24 '12 at 15:03
    
useful tip. I'd give your answer an upvote, too, but I don't have enough karma :-) –  huppy_doodoo Sep 24 '12 at 15:23
add comment

1 Answer

up vote 3 down vote accepted

You have just suffered from word splitting - Use More Quotes™ and use arrays if you want to send multiple parameters to a command:

LOG_PARAMS=("--color" "--pretty=format:$FORMAT" "--abbrev-commit" "--no-walk")
...
    git log "${LOG_PARAMS[@]}" "$(commits)"

This works for me without the "$(commits)" part, which I guess is another function you created.

share|improve this answer
    
Thanks for the reply, but it doesn't quite work. If I run git log "$LOG_PARAMS" I get fatal: unrecognized argument: --color --pretty=format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset --abbrev-commit --no-walk. Is this because git is so 'special'? –  huppy_doodoo Sep 24 '12 at 14:55
    
Umm, sorry, didn't quite read that properly. I'll correct it. –  l0b0 Sep 24 '12 at 14:59
    
Excellent, that worked! Thank you very much! –  huppy_doodoo Sep 24 '12 at 15:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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