I am pretty sure I’ve seen this done before, but I can’t seem to find it by google.
for file in $mydir/*
do
#redirect the rest to $myotherdir/$file.output.
echo this should go to the $myotherdir/$file.output.
done
It would also be great if I could use tee instead of a redirect, so that it goes to that file and stdout.
You can use any of at least three techniques. One is illustrated by dtmilano‘s answer, using a full sub-shell and parentheses, but be careful about clobbering previous output:
Or you can use braces to group the I/O redirection without starting a sub-shell:
Or you can sometimes use
exec:I’d normally use the
{ ... }notation, but it is cranky in a 1-line scenario; the}must appear where a command could start:The second semicolon is needed there.