Artificial intelligent assistant

new lines and bash variable I have a text file (or pipe output, doesn't matter here) memcached.uptime 1061374 memcached.curr_connections 480 memcached.cmd_get 478962548 memcached.cmd_set 17641364 memcached.cmd_flush 0 If I use command `cat test.txt | while read i; do echo $i; done` it produces quite expected output: memcached.uptime 1061374 memcached.curr_connections 480 memcached.cmd_get 478962548 etc But if I loop over using `for i in $(cat test.txt); do echo $i; done` I see something different: memcached.uptime 1061374 memcached.curr_connections 480 memcached.cmd_get 478962548 etc The question is: WHY???

The answer is that `$(command)` expands to the raw output of the command, which your shell will then perform its usual word separation on. Said separation consists of _any_ whitespace being considered a word separator.

You are also doing two different things with the text; in one you are parsing it through `read` (which works on _line_ input and not _word_ input, and in the other, you are iterating over the output of `$(cat)` in a `for` loop. You could probably get similar results with `IFS='\
' for i in $(cat test.txt); do echo "$i"; done`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 561d44895b3d1e8ae63b81ce02bf7e58