# Potential asterisk expansion bug in Windows Git Bash?

3 messages from 2019-08-14 to 2019-08-14. Participants: Bo Zhang, Jeff King.
Thread: https://gitlist.dev/t/51642

## Bo Zhang, 2019-08-14 11:50

Subject: Potential asterisk expansion bug in Windows Git Bash?
Message-ID: <CAO=KXnspgZa=R9=8wvPY-Y8pvuAah-D+Jc4CM_+cdemYGUJ09A@mail.gmail.com>
URL: https://gitlist.dev/e/CAO%3DKXnspgZa%3DR9%3D8wvPY-Y8pvuAah-D%2BJc4CM_%2BcdemYGUJ09A%40mail.gmail.com

```
Hi there,

Not sure if this is the correct channel to submit a bug report for
Windows Git Bash. Please let me know if I did anything wrong.

Today I noticed that on Windows Git Bash, the asterisk (*) is
incorrectly expanded even when it’s in a quote or following a
backslash (\). I’m wondering if this is the correct behaviour (which
seems like to me NOT).

Step to reproduce (in Windows git bash):

zhb@zhb-PC MINGW64 ~/Desktop
$ bash --version
GNU bash, version 4.4.19(2)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

zhb@zhb-PC MINGW64 ~/Desktop
$ cat 1.sh
echo $1

zhb@zhb-PC MINGW64 ~/Desktop
$ bash 1.sh '*'
$A 1.sh 1.txt

zhb@zhb-PC MINGW64 ~/Desktop
$ bash 1.sh "*"
$A 1.sh 1.txt

zhb@zhb-PC MINGW64 ~/Desktop
$ bash 1.sh \*
1.sh 1.txt

Thank you very much.

Regards,
Bo Zhang

```

## Jeff King, 2019-08-14 12:10

Subject: Re: Potential asterisk expansion bug in Windows Git Bash?
Message-ID: <20190814121045.GA30302@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190814121045.GA30302%40sigill.intra.peff.net
In-Reply-To: <CAO=KXnspgZa=R9=8wvPY-Y8pvuAah-D+Jc4CM_+cdemYGUJ09A@mail.gmail.com>

```
On Wed, Aug 14, 2019 at 07:50:47PM +0800, Bo Zhang wrote:

> Today I noticed that on Windows Git Bash, the asterisk (*) is
> incorrectly expanded even when it’s in a quote or following a
> backslash (\). I’m wondering if this is the correct behaviour (which
> seems like to me NOT).
> 
> Step to reproduce (in Windows git bash):
> 
> zhb@zhb-PC MINGW64 ~/Desktop
> $ bash --version
> GNU bash, version 4.4.19(2)-release (x86_64-pc-msys)
> Copyright (C) 2016 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> 
> This is free software; you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> 
> zhb@zhb-PC MINGW64 ~/Desktop
> $ cat 1.sh
> echo $1

Your script doesn't quote "$1", so whatever you pass in will be subject
to wildcard expansion inside the shell running the script.

Try this:

  $ cat bad.sh
  echo $1
  $ cat good.sh
  echo "$1"

  $ bash bad.sh '*'
  bad.sh good.sh

  $ bash good.sh '*'
  *

> zhb@zhb-PC MINGW64 ~/Desktop
> $ bash 1.sh '*'
> $A 1.sh 1.txt

So this is the case I showed above.

> zhb@zhb-PC MINGW64 ~/Desktop
> $ bash 1.sh "*"
> $A 1.sh 1.txt

And this is equivalent. The quotes suppress wildcard expansion in your
interactive shell, but the script itself does another round of
expansion.

> zhb@zhb-PC MINGW64 ~/Desktop
> $ bash 1.sh \*
> 1.sh 1.txt

And same here.

-Peff

```

## Bo Zhang, 2019-08-14 12:38

Subject: Re: Potential asterisk expansion bug in Windows Git Bash?
Message-ID: <CAO=KXnvrVdTRW=FhKMixSHuR-qahJ2QqUKOn4PerZAVcxVJHww@mail.gmail.com>
URL: https://gitlist.dev/e/CAO%3DKXnvrVdTRW%3DFhKMixSHuR-qahJ2QqUKOn4PerZAVcxVJHww%40mail.gmail.com
In-Reply-To: <20190814121045.GA30302@sigill.intra.peff.net>

```
Thank you very much Jeff!

It turns out I ran into
https://bugs.openjdk.java.net/browse/JDK-8131329 on Windows. The
example was also a mistake. Anyway, false alarm, thank you again!

Regards,
Bo

On Wed, Aug 14, 2019 at 8:10 PM Jeff King <peff@peff.net> wrote:
>
> On Wed, Aug 14, 2019 at 07:50:47PM +0800, Bo Zhang wrote:
>
> > Today I noticed that on Windows Git Bash, the asterisk (*) is
> > incorrectly expanded even when it’s in a quote or following a
> > backslash (\). I’m wondering if this is the correct behaviour (which
> > seems like to me NOT).
> >
> > Step to reproduce (in Windows git bash):
> >
> > zhb@zhb-PC MINGW64 ~/Desktop
> > $ bash --version
> > GNU bash, version 4.4.19(2)-release (x86_64-pc-msys)
> > Copyright (C) 2016 Free Software Foundation, Inc.
> > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> >
> > This is free software; you are free to change and redistribute it.
> > There is NO WARRANTY, to the extent permitted by law.
> >
> > zhb@zhb-PC MINGW64 ~/Desktop
> > $ cat 1.sh
> > echo $1
>
> Your script doesn't quote "$1", so whatever you pass in will be subject
> to wildcard expansion inside the shell running the script.
>
> Try this:
>
>   $ cat bad.sh
>   echo $1
>   $ cat good.sh
>   echo "$1"
>
>   $ bash bad.sh '*'
>   bad.sh good.sh
>
>   $ bash good.sh '*'
>   *
>
> > zhb@zhb-PC MINGW64 ~/Desktop
> > $ bash 1.sh '*'
> > $A 1.sh 1.txt
>
> So this is the case I showed above.
>
> > zhb@zhb-PC MINGW64 ~/Desktop
> > $ bash 1.sh "*"
> > $A 1.sh 1.txt
>
> And this is equivalent. The quotes suppress wildcard expansion in your
> interactive shell, but the script itself does another round of
> expansion.
>
> > zhb@zhb-PC MINGW64 ~/Desktop
> > $ bash 1.sh \*
> > 1.sh 1.txt
>
> And same here.
>
> -Peff

```
