【问题标题】:Tee command basic behaviortee 命令基本行为
【发布时间】:2018-03-25 16:17:25
【问题描述】:

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

【问题讨论】:

  • 展示你的实现尝试。

标签: linux bash shell command


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 2014-06-20
    • 1970-01-01
    相关资源
    最近更新 更多