如何测试鱼壳中是否存在子串?例如,在switch表达式中:
set myvar "a long test string"
switch $myvar
case magical-operator-here "test string"
echo 'yep!'
case '*'
echo 'nope!'
end
Run Code Online (Sandbox Code Playgroud)
fah*_*aho 17
这*是通配符,所以
set myvar "a long test string"
switch $myvar
case "*test string"
echo 'yep!'
case '*'
echo 'nope!'
end
Run Code Online (Sandbox Code Playgroud)
如果你想测试是否结束与该字符串.如果它也可以出现在中间某处,最后添加另一个*.
此外,从2.3.0开始,fish已经string内置了一个match子命令,所以你也可以使用string match -q -- "*test string" $myvar.它还支持带有"-r"选项的pcre样式的正则表达式.