store the values from command into an array bash

2019-08-26 13:00发布

问题:

svn mergeinfo --show-revs eligible http://svn.test.com/INT_1.0.0/ http://svn.test.com/DEV/  | cut -d"r" -f2 | cut -d" " -f1

6097
6099

when i put this in a script, i get only last value but not all:

#!/usr/bin/bash

 src_url="http://svn.test.com/INT_1.0.0/"
 target_url="http://svn.test.com/DEV/"

 eligible_revs=(`svn mergeinfo --show-revs eligible  $src_url $target_url | cut -d"r" -f2 | cut -d" " -f1`)

 echo ${eligible_revs[@]}

output:
6099

回答1:

If you are running Cygwin the line endings can mess it up

$ foo=(`printf 'bar\r\nbaz'`)

$ echo ${foo[*]}
 baz