gpt4 book ai didi

linux - Tee 命令基本行为

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:14 26 4
gpt4 key购买 nike

我想通过使用 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

关于linux - Tee 命令基本行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com