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
Personally, I prefer to avoid
while read
when possible. I'd do it like this:The results of
declare -p svnTags
are then:Because what happens after
|
is a subshell. Variables changed in a subshell do not propagate back to the parent shell.Common workaround: