0

I'm trying to create a simple bash script that creates some folders inside another folder but i don't understand what's wrong with an if statement.

#~/bin/bash
MAXNUMBER=10
        for((nr=0; nr<$MAXNUMBER; nr++))
        do
               mkdir "folder"${nr}
               if [${nr} -eq 4]
               then
                       for((i=0; i<3; i++))
                        do
                                mkdir -p "./folder4/folder"${i}
                        done
                fi
done

Whenever i run this script it gives me this:

./script4.sh: line 6: [0: command not found]

Line 6 is the if statement which looks like it's not working how it should

Truica Sorin
  • 499
  • 2
  • 11
  • 24
  • 2
    give the square brackets some personal space! – karakfa Dec 19 '18 at 21:35
  • More obvious dupe: [Why should there be a space after '\[' and before '\]' in Bash?](https://stackoverflow.com/questions/9581064/why-should-be-there-a-space-after-and-before-in-the-bash-script) – chepner Dec 19 '18 at 21:38
  • 2
    In an alternative universe `bash` provides you this: `mkdir folder{0..9}; mkdir -p folder4/folder{0..2}` – karakfa Dec 19 '18 at 21:40

0 Answers0