title: How to expand PS1?
body: <p>I have a shell script that runs the same command in several directories (<a href="http://github.com/l0b0/fgit/blob/master/fgit.sh" rel="noreferrer">fgit</a>). For each directory, I would like it to show the current prompt + the command which will be run there. How do I get the string that corresponds to the <strong>decoded</strong> (expanded)<code>PS1</code>? For example, my default PS1 is</p>
  
  <pre class="lang-sh prettyprint-override"><code>${debian_chroot:+($debian_chroot)}\[\e[1;32m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]$(__git_ps1 ' (%s)')$
  </code></pre>
  
  <p>and I'd like to echo the resulting prompt <code>username@hostname:/path$</code>, preferably (but not necessarily) with the nice colors. A cursory look at the Bash manual didn't reveal any definite answer, and <code>echo -e $PS1</code> only evaluates the colors.</p>