使用zsh计算字符串中的斜杠数

时间:2016-07-07 12:08:59

标签: zsh

我尝试用zsh获取字符串中的斜杠数。我认为它应该像这样工作(替换所有非/字符,然后计算它们)

foo="sdfds/sf/sdf/sdf/sd/f//sdf/"
print ${#foo//[^/]/}

但我得preexec:26: bad pattern: [^。它似乎适用于除/之外的所有字符。我试图用反斜杠来逃避它但是直到我添加了3个反斜杠它才起作用:

print ${#foo//[^\\\/]/}

为什么我需要在字符串中找到转义斜杠?

编辑:是的,似乎使用zsh -f使用一个反斜杠。 我的setopt:

autocd
autopushd
nobeep
completeinword
correct
extendedglob
extendedhistory
nohistbeep
histfindnodups
histignorealldups
histignoredups
histignorespace
histnofunctions
histnostore
histreduceblanks
histsavenodups
histverify
nohup
incappendhistory
interactive
interactivecomments
longlistjobs
monitor
nonomatch
promptsubst
pushdignoredups
sharehistory
shinstdin
transientrprompt
zle

0 个答案:

没有答案