【发布时间】:2018-03-25 16:17:25
【问题描述】:
我想通过使用while循环和读取来模拟shell脚本中tee命令的行为,或者是否可以看到命令的内容。
【问题讨论】:
-
展示你的实现尝试。
我想通过使用while循环和读取来模拟shell脚本中tee命令的行为,或者是否可以看到命令的内容。
【问题讨论】:
不确定你在问什么,但对于一个简单的例子,试试这个 -
file=$1 # take an argument that specifies the file to write into
exec 3>&1 # create a dup of stdout
while read line # now for each line of input
do echo "$line" >&3 # send a copy to the dup of stdout
echo "$line" # and a copy into the specified file
done > $file # this is the file redirection for the loop
【讨论】: