git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Han <laughinghan@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Two potential bugs in aliases that expand to shell commands
Date: Thu, 4 Apr 2013 02:40:07 -0400	[thread overview]
Message-ID: <20130404064007.GA8278@sigill.intra.peff.net> (raw)
In-Reply-To: <CACE=nd1dwhCyrKdzFq7O4UgD1TH8-c5R+4L2rH0NGW-jWqLr_g@mail.gmail.com>

On Wed, Apr 03, 2013 at 07:05:33PM -0700, Han wrote:

> There appears to be another case string values need to be enclosed in
> quotes, which is a shell command where you want to preserve quote
> characters (not leading or trailing); a minimal example is
> 
>   shortcut = !cd "" && pwd

Yes. You must escape any double-quotes that are not the beginning or
end of a quoted string.

>   shortcut = !"cd \"\" && pwd"

This is fine. Technically so is:

  shortcut = !cd \"\" && pwd

but I think it is more readable to put such shell snippets inside a
double-quoted string, to make it more clear what is going on.

Documentation patches welcome.

> The other bug I'm much more confused by. If you have an alias like
> 
>   shortcut = !"echo -n lol; echo wut"
> 
> it will, in fact, print
> 
> -n lol
> wut
> 
> which is, uh, not what bash prints. Is git special-casing echo?

No, git does not special-case echo. But it runs shell commands with
/bin/sh, which may or may not be bash on your system (and "-n" is not
necessarily portable to other POSIX shells).

If you really want to use bash, do:

  shortcut = "!bash -c 'echo -n lol; echo wut'"

or just use printf, which is a portable way to spell "echo -n".

-Peff

      reply	other threads:[~2013-04-04  6:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-04  2:05 Two potential bugs in aliases that expand to shell commands Han
2013-04-04  6:40 ` Jeff King [this message]

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=20130404064007.GA8278@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=laughinghan@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).