#!/bin/bash
#this file name is redirecttmp.sh
LOG1=/temp/temp1.log
LOG2=/temp/temp2.log
echo "this is first line in LOG1">>${LOG1} 2>&1
print "this is wrong line in LOG1">>${LOG1} 2>&1 #将抛出错误信息因为bash不支持print命令
echo "this is third line in LOG1">>${LOG1} 2>&1
echo "this is first line in LOG2">${LOG2} 2>&1
print "this is wrong line in LOG2">${LOG2} 2>&1 #将抛出错误信息因为bash不支持print命令
echo "this is third line in LOG2">${LOG2} 2>&1
---------------------------------------------------------------------------------------------------------------------------
temp1.log内容为
this is first line in LOG1
./redirecttmp.sh: line 7:print: command not found
this is third line in LOG1
temp2.log内容为
this is third line in LOG2
从结果可知: >>${LOG1} 2>&1 正确或错误结果追加到LOG文件里 >${LOG2} 2>&1 正确或错误结果覆写LOG文件