2017-10-13 4 views
-4

Je veux simuler le comportement de commande tee dans un script shell en utilisant en boucle et lire, ou s'il est possible de voir le contenu de la commande.commande T de comportement de base

+0

Montrez votre tentative de mise en œuvre. – Cyrus

Répondre

1

Je ne sais pas ce que vous demandez, mais pour un exemple simpliste, essayer -

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