=〜运算子附近的语法错误

编程入门 行业动态 更新时间:2024-10-22 17:36:47
本文介绍了=〜运算子附近的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我运行此脚本时:

#!/bin/bash if [[ "abcd" =~ ^.*$ ]]; then echo "something" fi

我得到:

./tmp2.sh: line 3: conditional binary operator expected ./tmp2.sh: line 3: syntax error near `=~' ./tmp2.sh: line 3: `if [[ "abcd" =~ ^.*$ ]]; then'

我尝试了所有发现的建议,但仍然相同:/ 请帮帮我!

I've tried all suggestions I've found, but still the same:/ Help me, please!

推荐答案

鉴于您看到的是 bash特定的错误消息,我们可以排除 bash 之外的 strong 以外的其他东西正在运行脚本(如果它是仅POSIX功能的外壳,例如在某些系统上为sh,则您会看到一个与[[有关的错误消息.

Given that you're seeing a bash-specific error message, we can rule out that something other than bash is running the script (if it were a POSIX-features-only shell, such as sh on some systems, you'd instead see an error message relating to [[).

最可能的解释:

  • 您的 bash版本是< 3.0 ,因此不支持=~运算符.
    • 要进行验证,请在脚本中运行echo $BASH_VERSION.
    • Your bash version is < 3.0, and therefore doesn't support the =~ operator.
      • To verify, run echo $BASH_VERSION in your script.

      您看到的特定错误是bash的表达方式:我看到的字符串我不认识为运算符."

      The specific error you're seeing is bash's way of saying: "I'm seeing a string I don't recognize as an operator."

更多推荐

=〜运算子附近的语法错误

本文发布于:2023-10-14 22:22:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!