How do i redirect the output of a for loop to a file in a bash script?
-
Let's say we want to send the out of the scripts we used in article How do i use a different field separator in bash for loop? to a file.
We just need to redirect all of the output from the for loop, after the done. see line number 5
#!/bin/bash for fruit in $(cat fruit.txt) do echo "Result: $fruit" done > myoutput.txt
Use
>>
if you need to append to the output file.
© Lightnetics 2024