2017-10-13 5 views
-4

Ich möchte das Verhalten von Tee-Befehl in einem Shell-Skript mit While-Schleife und lesen, oder wenn es möglich ist, den Inhalt des Befehls zu sehen.T-Befehl grundlegendes Verhalten

+0

Zeigen Sie Ihre Implementierung Versuch. – Cyrus

Antwort

1

Nicht sicher, was Sie fragen, aber für ein einfaches Beispiel, versuchen Sie dies -

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