On 25 June 2017 at 21:25, J.B. <address@hidden> wrote:
Expanding an array for use in a for-loop behaves differently depending on
how the array was created. How can I get bash to expand using a different
delimiter? I tried `find -print0' after setting IFS= but bash just ignores
Your array is not being expanded differently in the for-loop. You're
creating it incorrectly.
What's happening ?
First bash evaluates the command $() and substitutes that expression
with the value from stdout.
Secondly, it breaks apart that string into tokens given the values in IFS.
Thirdly it assigns each token to a different position in the array.
This is most likely what you want:
IFS=$'\x0a'
listoffiles=( $(find ...) )
Or if you're picky about wanting not to treat the newline as a
separator, this helps you further
https://stackoverflow.com/questions/1116992/capturing-output-of-find-print0-into-a-bash-array
On 25 June 2017 at 22:03, Andy Chu <address@hidden> wrote:
Example of subshell:
find -print0 | (i=0; while read -d '' line; do echo $line; ((i++)); done;
echo $i )
You're reading the values into a sub-shell, which are not inherited by
the main shell.