Question: I'm making a script that executes a file a certain amount of times, then if the file executes properly, it generates another file, and this last file I need to store it in a directory. Example: I execute it like this: ./shell 5 DIR
Then, the crpit shell executes another file called simulation 5 times and it creates a directory and an output file for each time the file simulation was executed correctly.
The thing is, I have to put an if statement for the parameters they send when they execute the file, and I don't know how to, here's the code I have:

```
#!/bin/bash

if [ $# == 3 || $# == 2 ]; then
    c=0
    i=0
    e=0
    cont=0
    while [ $c -le $0 ]
    do
            ./simula cont RES
        e = $?
        if[ e == 0 ]; then
            if[ $# == 3 ]; then
                chmod RES $2
            mkdir $1$c
            mv RES $1$c/.
            (( c++ ))
        else
            (( i++ ))
        (( cont++ ))
    done
    echo Shan generat $c simulacions correctes.
    echo Hi ha hagut $i simulacions erronies.        
else 
    echo Nombre de parametres incorrecte: $#.
fi

```

So I must have either 2 or 3 paremeters when executing the file called shell, and thats why i have that if in the second line of code, however it keeps giving me an error:

```
./shell: line 12: syntax error near unexpected token `then'
./shell: line 12: `             if[ e == 0 ]; then'

```

I'm new to scripts and I have no idea what am I doing wrong, any clues?

Answer: 
Spacing is very important in shell scripts, it's not like programming languages where  

`if(x>y)` and `if ( x > y )` are the same thing.

In particular, `if` and `[` are two different commands:  

`if[ e == 0 ]` needs to be `if [ e == 0 ]`

More precisely, `if` is a shell *keyword* as are `then`, `else`, and `fi`

`[` is either a shell *builtin* or an external program (or both) depending on your shell and is an alias for `test`. You can find out more with the `which` and `type` commands.

```
$ type [
[ is a shell builtin
$ which [
/bin/[
$ type fi
fi is a shell keyword
$ which fi
$

```
When assigning variables, Bash doesn't allow leaving spaces in between the `=` sign like is common practice in other languages.

There must be a space separating reserved words like `if`.

So `if [ $# == 3 ]` is valid where `if[ $# == 3 ]` is not.

In Bash, it's important to use `$` in front of variable names when you're calling the variable after it's been assigned.

So `[ e == 0 ]` would test to see if the literal string `e` is the same as the string `0`. To test if the string assigned to variable `e` is the same as the string `0`, use `[ $e == 0 ]` .

When `test`ing integers, you can use `-eq` instead of `==`. See `man test` for more information.

Also, `$0` expands to the name of the script file, so you're `while` loop will never end if the script name is not `0` as the script name will not change while your script is running.