加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

为什么我在bash字符串相等性测试中遇到意外的操作符错误?

发布时间:2020-12-15 18:25:16 所属栏目:安全 来源:网络整理
导读:参见英文答案 /bin/sh: Odd string comparison error ‘unexpected operator’ 3个 第四行的错误在哪里? if [ $bn == README ]; then 如果我把它写成,我仍然会得到 if [ $bn == README ]then 要么 if [ "$bn" == "README" ]; then 语境: for fi in /etc/uw
参见英文答案 > /bin/sh: Odd string comparison error ‘unexpected operator’ 3个
第四行的错误在哪里?
if [ $bn == README ]; then

如果我把它写成,我仍然会得到

if [ $bn == README ]
then

要么

if [ "$bn" == "README" ]; then

语境:

for fi in  /etc/uwsgi/apps-available/* 
do 
        bn=`basename $fi .ini`
        if [ $bn == "README" ]
        then
                echo "~ ***#*** ~"
        else
                echo "## Shortend for convience ##"
        fi
done
您不能使用==进行单括号比较([]).使用single =代替.您还必须引用变量以防止扩展.
if [ "$bn" = README ]; then

如果你使用[[]],那可能适用,你不需要引用第一个参数:

if [[ $bn == README ]]; then

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读