title: How do I use a date in an Expect script?
body: <p>I need to have access to the current date (or time) within the Expect script so that I can add it to the directories that are created within the Expect script, e.g. something similar to these needs to get done:</p>
  <pre><code>mkdir file&lt;date&gt;
  </code></pre>
  <p>I can get the date via the shell as:</p>
  <pre class="lang-sh prettyprint-override"><code>date | tr &quot; &quot; &quot;-&quot; | cut -f 2,4 -d &quot;-&quot;
  </code></pre>
  <p>However, I cannot get access to it in Expect, e.g. I cannot do something like:</p>
  <pre class="lang-sh prettyprint-override"><code>set var = `date | tr &quot; &quot; &quot;-&quot; | cut -f 2,4 -d &quot;-&quot;`
  </code></pre>
  <p>I put this in a shell script, echo it and get the output in <code>$expect_out(buffer)</code> as detailed <a href="http://wiki.tcl.tk/17378" rel="nofollow noreferrer">here</a>. However, the buffer also gets the prompt which needs to be removed as mentioned <em>Also, note that <code>$expect_out(buffer)</code> doesn't really hold what people want; it typically needs to be filtered down at least to eliminate the prompt.</em></p>