嗨!如果var变量的内容与以ABC结尾的字符串进行模式匹配,我想创建一个控制的bash脚本吗?
答案 0 :(得分:1)
你快到了
var="hellowordABC"
echo $var | grep ".*ABC$"
或使用内置条件
[[ $var =~ ABC$ ]] && echo "var ends with ABC"
答案 1 :(得分:1)
您可以使用bash builtins:
# with glob patterns
if [[ $var == *ABC ]]; then echo "$var ends with ABC"; fi
# with regular expression
if [[ $var =~ ABC$ ]]; then echo "$var ends with ABC"; fi