简体   繁体   中英

Tee command basic behavior

我想通过使用 while 循环和读取来模拟 tee 命令在 shell 脚本中的行为,或者是否可以查看命令的内容。

Not sure what you're asking, but for a simplistic example, try this -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM