Bash: can't build array in right side of pipe
arrays, bash, shell
Solution
Because what happens after `|` is a subshell. Variables changed in a subshell do not propagate back to the parent shell.
Common workaround:
while read line ; do
...
done < <(svn ls http://...)
Problem
Anyone have a clue as to why this code is not working as expected? ``` $> svnTags=() $> svn ls http://plugins.svn.wordpress.org/duplicate-post/tags/ | while read line; do slashless=$(sed 's#/$##g' <<< $line); echo "slashless - $slashless"; svnTags+=($slashless); done slashless - 1.0 slashless - 1.1 slashless - 1.1.1 slashless - 1.1.2 slashless - 2.0 slashless - 2.0.1 slashless - 2.0.2 slashless - 2.1 slashless - 2.1.1 slashless - 2.2 slashless - 2.3 $> echo "$svnTags[@]" ``` Not giving any output, I'm expecting it to output the built array of the svn tags. Second command broken out: ``` svn ls http://plugins.svn.wordpress.org/duplicate-post/tags/ | while read line; do slashless=$(sed 's#/$##g' <<< $line) echo "slashless - $slashless" svnTags+=($slashless) done ```