Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: coreplayer2 on December 07, 2011, 07:34:54 PM

Title: bash tee command?
Post by: coreplayer2 on December 07, 2011, 07:34:54 PM
Ok, anyone familiar with the "tee" command?

I've been attempting to modify this function of a script.   Currently this line outputs the result of lspci to grep  via a pipe, with all errors > black hole.   In addition to output > grep I would like to print the same output to a file to be used later.
 
controllermode=`lspci 2>//dev/null | egrep -i -o "(IDE interface)|(AHCI controller)"`

For the time being, I've added a separate line to deal with this, however I understand there is a "tee" command which splits the stream two ways, does anyone know how to apply this "tee" making the script more efficient?

lspci >//home/tc/pci.log 2>//dev/null

The function:
Code: [Select]
fsata(){
lspci >//home/tc/pci.log 2>//dev/null  #added this line until tee works
controllermode=`lspci 2>//dev/null | egrep -i -o "(IDE interface)|(AHCI controller)"`
echo
echo "Current controller mode(s):"
echo "$controllermode"
echo
}

fsata

I'm new to bash, which is why I've taken a long handed approach (like path's)  so if anyone would advise on how to write efficiently, please feel free, I'm all ears.
;)

The more I rationalize this, I'm thinking something like this might work.

lspci 2>//dev/null | tee ~/pci.log | egrep -i -o "(IDE interface)|(AHCI controller)"
?

Ok this does appear to work, but is it correct or as efficient as it could be.?
Title: Re: bash tee command?
Post by: gerald_clark on December 08, 2011, 12:28:11 AM
This is not a tc/mc issue and could easily be answered by reading the online bash docs.
Title: Re: bash tee command?
Post by: coreplayer2 on December 08, 2011, 01:20:19 AM
Thank's I've been reading these the man pages and other docs for a while and am fairly sure I have a good grasp on the command,  Just asking those who are more experienced is all.  Especially as there may be something specific to tc which may be affecting the outcome which I am not aware off.

Forgive me I thought this was the Unofficial Programming & Scripting section..