相关疑难解决方法(0)

如何在bash脚本中使用正则表达式?

我想使用正则表达式检查变量是否具有有效年份.阅读bash手册我明白我可以使用operator =〜

看下面的例子,我希望看到"不行",但我看到"OK".我究竟做错了什么?

i="test"
if [ $i=~"200[78]" ]
then
  echo "OK"
else
  echo "not OK"
fi
Run Code Online (Sandbox Code Playgroud)

regex bash conditional

83
推荐指数
2
解决办法
11万
查看次数

标签 统计

bash ×1

conditional ×1

regex ×1