【问题标题】:store the values from command into an array bash将命令中的值存储到数组bash中
【发布时间】:2013-06-11 15:01:42
【问题描述】:
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

当我把它放在脚本中时,我只得到最后一个值,但不是全部:

#!/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

【问题讨论】:

    标签: arrays bash shell svn unix


    【解决方案1】:

    如果你运行的是 Cygwin,行尾可能会搞砸

    $ foo=(`printf 'bar\r\nbaz'`)
    
    $ echo ${foo[*]}
     baz
    

    【讨论】:

    • 如何获取数组中命令输出的值或所有值 - 6097,6099?
    • @jaav:尝试在设置eligible_revs之前将\r添加到字段分隔符列表中:IFS+=$'\r'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 2012-04-03
    • 2021-11-19
    • 2018-08-30
    • 1970-01-01
    相关资源
    最近更新 更多