Pb Vignesh
Pb Vignesh

Reputation: 185

Bash script greater than operator gives syntax error

I googled a lot and found it because of the spaces within the if condition but then even after resolving that, it still gives me some errors as I've pasted below. Just beginning to learn bash scripts any help would be useful. Thanks.

#!/bin/bash
msg=3;
if[ $msg -gt 0 ]
then
echo $msg;
fi

ERROR

line 3: if[ 3 -gt 0 ]: command not found
line 4: syntax error near unexpected token `then'
line 4: `then'

Upvotes: 0

Views: 721

Answers (1)

Chris Lam
Chris Lam

Reputation: 3614

You missed a space after if:

if [ $msg -gt 0 ]

To better format your code:

msg=3

if [ $msg -gt 0 ]; then
    echo $msg;
fi

Upvotes: 1

Related Questions