1
如何測試魚殼中是否存在子串?例如,switch
表達式中:如何測試一個字符串是否包含魚殼中的另一個字符串?
set myvar "a long test string"
switch $myvar
case magical-operator-here "test string"
echo 'yep!'
case '*'
echo 'nope!'
end
如何測試魚殼中是否存在子串?例如,switch
表達式中:如何測試一個字符串是否包含魚殼中的另一個字符串?
set myvar "a long test string"
switch $myvar
case magical-operator-here "test string"
echo 'yep!'
case '*'
echo 'nope!'
end
的*
是通配符,所以
set myvar "a long test string"
switch $myvar
case "*test string"
echo 'yep!'
case '*'
echo 'nope!'
end
如果你想測試是否結束以該字符串。如果它也可以出現在中間的某個地方,則在最後添加另一個*
。
此外,自2.3.0開始,魚內部有string
子命令,因此您也可以使用string match -q -- "*test string" $myvar
。它還使用「-r」選項支持pcre風格的正則表達式。
我一直很感謝你的有關魚殼的StackOverflow答案。 – Chris