views:

54

answers:

1

I have a little bash function to log my Macports outputs to a file (since installs often spew little tidbits that are easy to lose in terminal noise), then I just cat the file to the terminal:

function porti {
    command sudo port install $@ >> $1.log 2>&1; cat $1.log
}

Is there a way to do this concurrently?

BTW I pass $@ to install but only $1 for the file name so that I can do something like:

porti git-gore +bash_completion

and only get the file git-core.log however someone else might prefer to include variants in the file name...

+7  A: 

The usual solution is to use tee(1):

sudo port install $@ 2>&1 | tee -a $1.log

should do what you want

Chris Dodd
You crazy Unix people amaze me! How did you know about the command tee(1)?
bias
tee is part of the standard shellutils GNU package of about 2 dozen random commands that are useful in shell scripts, and which have been around for decades
Chris Dodd