dimanche 11 janvier 2015

How to use tee to capture STDOUT from a code block to a filename defined within the block?


I want to send STDOUT for a script block to a file which name is defined by a variable within the block. However, when I use tee, it seems the variable outside the block doesn't exist anymore. Without tee, the variable still exists.


Script:



#!/bin/bash
{
log="mylog.txt"
echo log: $log
} |tee $log

echo log: $log


Result:



log: mylog.txt
log:


and no mylog.txt file produced by tee.



Aucun commentaire:

Enregistrer un commentaire