Bash: functional difference between process substitution and here string with $( ) ?
Hello :)
Further to solved LQ thread Bash: how to populate a list of arbitrarily named files?, what is the functional difference between feeding a loop with process substitution and feeding it with a here string with embedded command substitution? ABSG pages: process substitution, here string and command substitution. This works Code:
while IFS= read -r -d '' file Code:
while IFS= read -r -d '' file Charles |
Process substitution sets up a FIFO and expands to the device file that fifo is associated with (/dev/fd/42 or somesuch). As such, all data from the command is redirected, doesn't matter what's in it.
The command substitution and here-string breaks because bash first does the command substitution, which chomps newlines from the end and cuts everything past a null in the data, since nulls aren't allowed in a string. Then, the here-string actually creates a here-document which actually creates a temporary file containing the string plus one newline at the end (since we chomped all of them earlier, but a valid text file must end each line with a newline). Short story, the only way command substitution and here-string is equivalent to process substitution is when the content has exactly one newline at the end and no nulls whatsoever. |
Thank you for that very clear explanation tuxdev :)
|
All times are GMT -5. The time now is 10:26 AM. |