From: Jeff King <peff@peff.net>
To: Dun Peal <dunpealer@gmail.com>
Cc: Erik Faye-Lund <kusmabite@gmail.com>, git@vger.kernel.org
Subject: Re: Weird behavior of shell variables in git aliases
Date: Mon, 21 Mar 2011 17:53:10 -0400 [thread overview]
Message-ID: <20110321215310.GA2122@sigill.intra.peff.net> (raw)
In-Reply-To: <d9c38309-c433-476c-bba3-f2c5b7e94a89@k15g2000prk.googlegroups.com>
On Mon, Mar 21, 2011 at 09:39:43AM -0700, Dun Peal wrote:
> It seems that a variable is available only once?! How can the
> following shell session be explained:
>
> $ git config alias.test0
> !echo $1
> $ git test0 foo
> foo
> $ git config alias.test1
> !echo $1 && echo $1
> $ git test1 foo
>
> foo
> $ git config alias.test2
> !BRANCH=$1 && echo $BRANCH && echo $BRANCH
> $ git test2 foo
>
> foo
Because in v1.7.4 and earlier, we literally just tack the arguments
(shell-quoted) onto the end of the string. So your alias ends up
expanding to:
/bin/sh -c "!echo $1 && echo $1 'foo'"
So the first echo is empty, and then the second one echos foo. And what
you are trying to do doesn't work with a straight alias (at the bottom
I'll show you what you want).
But interestingly, that's _not_ the behavior as of Erik's 7f51f8b
(alias: use run_command api to execute aliases, 2011-01-07), which is in
master but not yet released. With that, we end up executing:
sh -c 'echo $1 && echo $1 "$@"' 'echo $1 && echo $1' 'foo'
which prints "foo foo". So it is technically a regression. I don't know
how much we care; using positional parameters like this was already
nonsensical, as shown above.
For reference, what you actually want (in either system) is:
$ git config alias.test1
!sh -c 'echo $1 && echo $1' -
$ git test1 foo
foo
foo
Make sure to include the "-" (or some other string) which ends up as $0.
-Peff
next prev parent reply other threads:[~2011-03-21 21:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-21 16:39 Weird behavior of shell variables in git aliases Dun Peal
2011-03-21 21:53 ` Jeff King [this message]
2011-03-21 22:21 ` Junio C Hamano
2011-03-21 22:33 ` Junio C Hamano
2011-03-22 10:38 ` Lasse Makholm
2011-03-22 11:28 ` Jeff King
2011-03-22 12:59 ` Lasse Makholm
2011-03-22 10:52 ` Ævar Arnfjörð Bjarmason
2011-03-22 11:18 ` Jeff King
2011-03-22 13:28 ` Jeff King
2011-03-22 13:35 ` Lasse Makholm
2011-03-22 13:43 ` Jeff King
2011-03-22 13:53 ` Lasse Makholm
2011-03-22 15:06 ` Dun Peal
2011-03-22 17:57 ` Junio C Hamano
2011-03-22 18:32 ` Jeff King
2011-03-22 22:22 ` Lasse Makholm
2011-03-23 3:01 ` Junio C Hamano
2011-03-22 17:36 ` Junio C Hamano
2011-03-22 17:35 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110321215310.GA2122@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=dunpealer@gmail.com \
--cc=git@vger.kernel.org \
--cc=kusmabite@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).