bash中的if语句错误 [英] if statement error in bash

查看:102
本文介绍了bash中的if语句错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i=0
for f in `awk '{print $1}' config.list`
do
    echo "i value is $i"
    if ["$i" = "0"]
    then
        echo "here"
        i=$((i+1))
        continue 
    fi
    arr[i]=$f  
    i=$((i+1))
done

在上面的bash脚本中,我在使用if语句时出现了这样的错误

In the above bash script I am getting an error where i have used the if statement it looks like this

./script.sh: line 5: [0: command not found

请指出可能是我的错误.

Kindly point me out what could be my mistake.

推荐答案

使用if [ "$i" = "0" ]

在bash中,在if条件下,[]周围需要空格

In bash, you need spaces around [ and ] in if conditions

这篇关于bash中的if语句错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆