Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to redirect a command error in the script

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
0
0
US
In a shell script, i have this to capture the name of the errlog file:

DBERR_log=`ls $DBFILEMAINT_ERRFILE* | awk '{print $1}'`

if the file exist, then it captures the value well.
if the file doesn't exist, DBERR_log="", and it splits out the error from the command line:
"Some_file_name not found."

How do I direct the error to /dev/null so it doesn't split out the error when the file isn't found.

Thanks,
 
Hi,
try:

DBERR_log=`ls $DBFILEMAINT_ERRFILE* 2>/dev/null | awk '{print $1}'`

 
> or >>" directs the output and "2> or 2>>" directs the error output.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top