0

I'm trying to perform ZSH variable substitution, but I'm having to do it the lame way, by piping through cut. Is it possible to perform this operation entirely within 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

1 Answer 1

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

Alternatively:

expr $i : '\.\/\([^/]*\)/'
3
  • Wait, better - echo ${${i:2}%%/*} - i really wanted to get it nested. Thanks for your help Aug 7, 2014 at 21:13
  • You should really break this down. I have no idea what this means. Oct 23, 2016 at 1:29
  • 1
    @MikeFurlender he's trying to extract the first folder name. In the first example it's cutting the first 2 chars off and then deleting everything from the next / until the end. See here for more info zsh.sourceforge.net/Doc/Release/… In the regex is selecting (with the \( and \) ) everything between ./ and the next /. Since regex try to match the longest, the safest way is to only match characters that are not / (with [^/] )
    – NuTTyX
    Oct 23, 2016 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .