shell脚本中取消重定向的方法实例
在上一篇关于shell编程的例子中,有讲到把shell脚本进行扩展之后重定向到一个文件中,以便进行查看和调试https://www.nhooo.com/article/62435.htm。但是,若是有另一种情况:只是在某些地方进行重定向,而其他地方不进行重定向。那么我们就来修改一下上一篇中的例子来进行这种需求的满足:
#!/bin/bash
functionsetlogfile
{
if![-z"$1"];then
echo"logfilenameisnotempty!">>kthh
exec3>&1
exec4>&2
exec2>>$1
exec1>>$1
fi
}
num1=$1 logfile=$2 execlogfile=$3
setlogfile${execlogfile} set-x if[$num1-eq0];then echo"num1is0">>${logfile} elif[$num1-ge0];then echo"num1isgrate0">>${logfile} else echo"num1isless0">>${logfile} fi exec2>&4 exec1>&3 if[$num1-eq0];then echo"num1is0again">>${logfile} fi
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿