0

The example below does not work: ~/test is empty.

foreach i (`ls`)
foreach echo $i > ~/test
foreach end

As well this does not work (unlike bash):

foreach i (`ls`)
foreach echo $i
foreach end > ~/test
Josef Klimuk
  • 1,596

1 Answers1

0
  1. There is no way in tcsh to redirect the output of the whole foreach loop.
  2. Workaround is to use addition '>>' on every turn of the loop, like this:

    foreach i (`ls`)
    echo $i >> ~/test    
    end
    
Kulfy
  • 17,696
Josef Klimuk
  • 1,596
  • I don't understand what you were expecting as output of the single foreach line? foreach is putting the result of ls in the variable i (line by line), and as such there should be no output. And even if there was some output, you would be redirecting it, not copying it, so the echo $i would not print echo anything. This is not a "workaround", this is exactly how it should behave. – ChatterOne Jan 02 '19 at 09:26
  • Cause, in bash you can put redirect at the end (after the word 'done') and it will redirect the output of the whole foreach loop – Josef Klimuk Jan 02 '19 at 09:31