The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




Thread: Error Messages
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-26-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
A little bit cryptic ...
error=$(exec 4>&1 5>&2 ; command goes here 2>&4 1>&5)
This swaps the function of stdout and stderr while command is running. So with:
error=$(exec 4>&1 5>&2 ; ls -l somefile not-there 2>&4 1>&5)
the ls -l for somefile is displayed and the error message regarding not-there is stored in the variable.

In your case, a simple cp command that does not write to stdout, you could more simply do:
error=$(cp this that 2>&1)