by chubot · 5y ago · 0 comments
I would worry about making it correct before making it fast, the former being a big challenge!
Shells Use Temp Files to Implement Here Documents : http://www.oilshell.org/blog/2016/10/18.html
(Oil doesn't do this; it creates a process for here docs without touching disk. In theory this could be eliminated for here docs less than PIPE_BUF, which is probably a lot of them)
Here's a version that doesn't use "here string" and so doesn't create temporary files.
#!/bin/bash
shopt -s lastpipe
string="Los Angeles, London, Belfast, New York"
echo "${string/, /,}" | readarray -d, -t arrayA
echo ${arrayA[0]}
echo ${arrayA[1]}
Also, the lastpipe option runs the readarray in the context of the current process.