title: Bash: How to redirect stdin, stdout and stderr to a log file for an install log
body: <p>I currently have a bunch of installer scripts which log stderr/stdout to a log file that works well but I need to also redirect stdin for user responses to the same log file. The install scripts sometime call functions in a shared library (an include), which may also read user input. I thought about adding a custom read function but this will require altering the shared library and wondered if there's a way to do this from the calling script.</p>
  
  <p>At the moment the scripts are similar to this:</p>
  
  <pre><code>#!/usr/bin/bash
  
  . ./libInstall
  
  INSTALL_LOG="./install.log"
  ( (
  
  echo "INFO: Installing..."
  # Run some arbitrary commands...
  # Read some input...
  read ANSWER1
  read ANSWER2
  # Call function in libInstall which will prompt the user...
  funcWhichAsksAQuestion ANSWER3
  
  echo "INFO: Installation Complete"
  
  ) 2&gt;&amp;1 ) | tee -a "${INSTALL_LOG}"
  </code></pre>
  
  <p>If I change "( (" to reflect the line below I can tee off stdin to the log file:</p>
  
  <p>cat - 2> /dev/null | tee -a ${INSTALL_LOG} | ( (</p>
  
  <p>This works but requires 2 carriage returns once the script ends, presumably because the pipe is broken. 
  It's almost there but I'd it to work without having to press enter twice at the end to get back to the shell prompt.</p>
  
  <p>These scripts have to be fairly portable to work on RHEL >=5, AIX >=5.1, Solaris >=9 with the lowest bash version being v2.05 I believe.</p>
  
  <p>Any ideas how I can achieve this?</p>
  
  <p>Thanks</p>