Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ‘Command not found’ errors when there is no space after the opening square bracket [duplicate]

Tags:

linux

bash

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

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.

like image 387
monucool Avatar asked Sep 11 '25 05:09

monucool


1 Answers

Use if [ "$i" = "0" ]

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

like image 104
Hari Menon Avatar answered Sep 13 '25 19:09

Hari Menon