I am trying to avoid creating any new files to store output in order to minimize the risk of overwriting something in a directory with the same name. I am trying to just evaluate each line in a stream with a pipe instead of outputting to a file and then using a while read line do done < file
loop. Something like:
echo -e "1\n2\n3\n4\n5" | #evaluate current line separately#
Could I somehow read each line into an array and then evaluate the elements in the array? or is there a better way to avoid accidentally overwriting files?
Stream functions are defined for two-dimensional flow and for three-dimensional axial symmetric flow. The stream function can be used to plot the streamlines of the flow and find the velocity. For two-dimensional flow the velocity components can be calculated in Cartesian coordinates by. (10.5)
A streamline is a line that is tangential to the instantaneous velocity direction (velocity is a vector, and it has a magnitude and a direction). To visualize this in a flow, we could imagine the motion of a small marked element of fluid.
Because a streamline is always tangent to the velocity at a every point along its length, there can be no flow across a streamline. The mathematical equation that describes the streamline in any flow is called a stream function.
In bash
, the common way is to use the Process Substitution:
while read line ; do
...
done < <( commands producing the input)
You were halfway there...
echo -e "1\n2\n3\n4\n5" | while read line; do
...
done
Note that bash runs each part of the pipeline in a separate process, and any variables defined there will not persist after that block. (ksh93 will preserve them, as the loop will run in the current shell process.)
You can avoid overwriting files by using mktemp
or tempfile
to create temporary files with unique names. However, I would use process substitution as in choroba's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With