Adhin37
Adhin37

Reputation: 57

Writing a log file with tee

There is my problem, I work with ksh script and i try to make a log file with function tee and with :

So i used tee to handle all echo in my script and i wanted to redirect output from specific echo to go only in log file.

foo(){
        echo Hello               # screen + log file
        echo World >> "tee.txt"  # only log file
        echo !                   # screen + log file      
}             
rm -f "tee.txt"
foo | tee -a "tee.txt" 

Screen output

Hello
!

That's okay.

Log file

But in log file :

World
Hello
!

echo redirection writed before tee.

Conclusion

So, does there is something that is like echo who will only store output and not showing it to screen ? To get that output in log file with tee ?

Hello
World
!

Upvotes: 0

Views: 13247

Answers (1)

Saurabh Sharma
Saurabh Sharma

Reputation: 154

Try this. It worked for me on ksh.

rm -f "tee.txt"

foo()
{
    echo Hello
    stty -echo
    echo World >> "tee.txt"
    stty echo
    echo !
}
foo | tee -a "tee.txt" 

Upvotes: 1

Related Questions