WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: bash tee command?  (Read 1847 times)

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
bash tee command?
« on: December 07, 2011, 04: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.?
« Last Edit: December 07, 2011, 07:02:52 PM by coreplayer2 »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: bash tee command?
« Reply #1 on: December 07, 2011, 09:28:11 PM »
This is not a tc/mc issue and could easily be answered by reading the online bash docs.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: bash tee command?
« Reply #2 on: December 07, 2011, 10:20:19 PM »
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..