2017-10-13 87 views
-4

我想通過使用while循環和讀取或者如果可以看到命令的內容來模擬shell腳本中tee命令的行爲。Tee命令基本行爲

+0

顯示你的執行的嘗試。 – Cyrus

回答

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