【发布时间】:2014-04-02 09:06:25
【问题描述】:
我有 bash shell 脚本来修改字符串。
我想从字符串 44[tip] 3764d6b8ae82 2014-04-01 16:34 +0400 igor 中获取 14040116 (YYMMDDHH)
我当前的脚本看起来像
raw_info="44[tip] 3764d6b8ae82 2014-04-01 16:34 +0400 igor"
hg_date=`echo $raw_info | cut -d' ' -f 3`
hg_date=${hg_date//-/}
hg_date=${hg_date:2}
hg_hour=`echo $raw_info | cut -d' ' -f 4 | cut -d':' -f 1`
hg_rev=${hg_date}${hg_hour}
有效,但可以更短吗?
【问题讨论】: