On Fri, Jun 09, 2017 at 01:52:44AM +0700, Peter & Kelly Passchier wrote: > On 09/06/2560 00:42, Greg Wooledge wrote: > > foo=$(cat "$file"; printf x) foo=${foo%x} > > The workaround I came up with is: > mapfile <"$file"; IFS= foo=${MAPFILE[@]} > > This seems to be faster, but it probably has other disadvantages...
Well, it leaves IFS changed, because you didn't revert or unset it, or run the entire thing in a function with local IFS. Also, I'd use "${MAPFILE[*]}" to reinforce that you are joining an array into a string, rather than expanding the array as a list. Semantically, x=$@ is pretty "huh??" to me. It also leaves the array in memory, and requires bash 4. Those may not be significant.