Re: Two potential bugs in aliases that expand to shell commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]