title: Why does posh fail to perform pathname expansion when a part of the path is specified within double-quotes?
body: <p>Consider the following simple shell script:</p>
  
  <pre><code>rm -rf bar \"bar\"
  mkdir -p bar
  touch bar/baz
  echo "bar"/*
  </code></pre>
  
  <p>I get the expected output with bash, ksh, zsh and dash, but I don't get
  it with posh:</p>
  
  <pre><code>susam@debian:~$ bash foo.sh
  bar/baz
  susam@debian:~$ ksh foo.sh
  bar/baz
  susam@debian:~$ zsh foo.sh 
  bar/baz
  susam@debian:~$ dash foo.sh
  bar/baz
  susam@debian:~$ posh foo.sh
  bar/*
  </code></pre>
  
  <p>I am trying to understand if the behaviour of posh is correct as per the POSIX standard or if it is a bug.</p>
  
  <p>The relevant section in the POSIX documents seem to be "2.6 Word Expansion":</p>
  
  <ul>
  <li>POSIX.1-2004: <a href="http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06" rel="noreferrer">2.6 Word Expansions</a></li>
  <li>POSIX.1-2008: <a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06" rel="noreferrer">2.6 Word Expansions</a></li>
  </ul>
  
  <p>Both of them mention that pathname expansion occurs before quote removal.</p>
  
  <blockquote>
    <ol start="3">
    <li>Pathname expansion (see <em>Pathname Expansion</em>) shall be performed, unless <code>set -f</code> is in effect.</li>
    <li>Quote removal (see <em>Quote Removal</em>) shall always be performed last.</li>
    </ol>
  </blockquote>
  
  <p>Considering this, the posh behaviour looks right because <code>"bar"/*</code> does not literally match any path above before the quote removal, so path expansion does not occur.</p>
  
  <p>So this led me to suspect that if there were a directory literally named <code>"bar"</code>, i.e. the quotes were part of the directory name, then posh would have matched it. But the following altered script shows that this is not true.</p>
  
  <pre><code>rm -rf bar \"bar\"
  mkdir -p \"bar\"
  touch \"bar\"/baz
  echo "bar"/*
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>susam@debian1:~$ bash foo2.sh 
  bar/*
  susam@debian1:~$ ksh foo2.sh 
  bar/*
  susam@debian1:~$ zsh foo2.sh 
  foo2.sh:3: no matches found: bar/*
  susam@debian1:~$ dash foo2.sh 
  bar/*
  susam@debian1:~$ posh foo2.sh 
  bar/*
  </code></pre>
  
  <p>So the pattern <code>"bar"/*</code> in posh matches neither the path <code>bar/baz</code> nor the path <code>"bar"/baz</code>. What does it match then? Is the posh behaviour a bug or a feature?</p>
  
  <p>Here are the version details in case it helps you to helps me:</p>
  
  <pre><code>susam@debian:~$ cat /etc/debian_version 
  8.3
  susam@debian:~$ dpkg -l bash ksh zsh dash posh
  Desired=Unknown/Install/Remove/Purge/Hold
  | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
  |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
  ||/ Name                        Version            Architecture       Description
  +++-===========================-==================-==================-============================================================
  ii  bash                        4.3-11+b1          amd64              GNU Bourne Again SHell
  ii  dash                        0.5.7-4+b1         amd64              POSIX-compliant shell
  ii  ksh                         93u+20120801-1     amd64              Real, AT&amp;T version of the Korn shell
  ii  posh                        0.12.3             amd64              Policy-compliant Ordinary SHell
  ii  zsh                         5.0.7-5            amd64              shell with lots of features
  </code></pre>