匹配字符串的后缀与case语句

时间:2012-04-23 15:02:18

标签: bash switch-statement

如何将字符串的后缀与case语句匹配?

实施例

case "foobar" in
    "*bar")
        echo "yay!"
    ;;
esac

1 个答案:

答案 0 :(得分:4)

如果你丢失报价,效果会很好;

#!/bin/bash
case "foobar" in
    *bar)
        echo "yay!"
        ;;
esac