Search code examples
bashloopsfor-looppipetee

Pipe with `tee` in a `for` loop


This is probably a newbie's escaping problem. I'm trying run command in a for loop like this

$ for SET in `ls ../../mybook/WS/wsc_production/`; do ~/sandbox/scripts/ftype-switch/typesort.pl /media/mybook/WS/wsc_production/$SET ./wsc_sorter/$SET | tee -a sorter.log; done;

but I end up with sorter.log being empty. (I'm sure there is some output.) If I escape the pipe symbol (\|), I end up with no sorter.log at all.

What am I doing wrong?

$ bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

Edit: Oops, /media/mybook/ fell asleep, so there actually was no output. The code was correct in the first place. Thanks to all for comments, though.


Solution

  • My deepest apologies, the problem was somewhere else and my script actually did not output anything at all. Now it works.

    Two reasons why I got the illusion that the problem is in escaping:

    • of course, lack of confidence in bash scripting, which is effect of lack of knowledge and experience
    • and also, lack of attention--it did not come into my mind that the disk on USB fell asleep, so when I tried the loop there actually was no output

    Well, that's for some stumbling on my way to knowledge... :)