Shell

zsh替換,不能用重複做正則表達式

  • August 7, 2014

我正在嘗試執行 ZSH 變數替換,但我不得不以蹩腳的方式通過cut. 是否可以完全在 ZSH 內執行此操作?

i=./riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05 echo ${${i/\.\//}:s/\/*//} riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05 echo ${${i/\.\//}} riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05 echo ${echo ${i/\.\//} | cut -d/ -f 1} zsh: bad substitution: echo $(echo ${i/\.\//} | cut -d/ -f 1) riak.logs.cloudstoragea08

i=./riak.logs.cloudstoragea08/2014-08-07T15:47:49.540310/console.log.2014-07-31-05
j=${i:2}
echo ${j%%/*}

或者:

expr $i : '\.\/\([^/]*\)/'

引用自:https://serverfault.com/questions/618812