【问题标题】:bash, issue with for loopbash,for循环的问题
【发布时间】:2015-07-21 09:09:43
【问题描述】:

我以这种方式列出了来自 amazon s3 的一些文件:

s3cmd ls s3://my-bucket/$(date +%Y%m%d -d "1 day ago")*

此命令返回:

2015-07-20 23:51  10680004   s3://my-bucket/20150720-1437436434_ip.log.gz
2015-07-20 23:55   6180965   s3://my-bucket/20150720-1437436477_ip.log.gz

为了循环这些文件,我的代码是:

for file in $(s3cmd ls s3://my-bucket/$(date +%Y%m%d -d "1 day ago")*)
do echo ${file}
done

但结果是:

2015-07-20
23:51
10680004
s3://my-bucket/20150720-1437436434_ip.log.gz
2015-07-20
23:55
6180965
s3://my-bucket/20150720-1437436477_ip.log.gz

而不是预期的结果:

s3://my-bucket/20150720-1437436434_ip.log.gz
s3://my-bucket/20150720-1437436477_ip.log.gz

我怎样才能检索到预期的结果?

【问题讨论】:

    标签: bash for-loop ls


    【解决方案1】:

    尝试替换

      $(s3cmd ls s3://my-bucket/$(date +%Y%m%d -d "1 day ago")*)
    

     $(s3cmd ls s3://my-bucket/$(date +%Y%m%d -d "1 day ago")* | sed 's/^.* s3/s3/' )
    

    通过截断日期大小部分来替换初始输出。

    【讨论】:

      猜你喜欢
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多