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
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://...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With