title: key logging in unix
body: <p>I am a newbie to unix scripting, I want to do following and I have little clue how to proceed.</p>
  
  <p>I want to log the input and output of certain set of commands, given on the terminal, to a trace file. I should be able to switch it on and off.</p>
  
  <p>E.g.</p>
  
  <pre><code>switch trace on
  
  user:echo Hello World
  
  user:Hello World
  
  switch trace off
  </code></pre>
  
  <p>Then the trace log file, e.g. trace.log, it's content should be</p>
  
  <pre><code>echo Hello World
  
  Hello World
  </code></pre>
  
  <p>One thing that I can think to do is to use <code>set -x</code>, redirecting its output to some file, but couldn't find a way to do that. I did <code>man set</code>, or <code>man -x</code> but I found no entry. Maybe I am being too naive, but some guidance will be very helpful.
  I am using bash shell.</p>