我想通过使用while循环和read来模拟shell脚本中tee命令的行为,或者是否可以看到命令的内容。
答案 0 :(得分:1)
不确定你在问什么,但是为了一个简单的例子,试试这个 -
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