Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote this simple script it works too but shows an error

echo Enter 1st number
read n1
echo Enter 2nd number
read n2
echo MUlti is `expr $n1 \* $n2`;
if [$n1 -lt $n2]
 echo $n1 'is bigger than' $n2
 echo $n2 'is bigger than' $n1


Enter 1st number
Enter 2nd number
MUlti is 50
./ line 7: [5: command not found
10 is bigger than 5
share|improve this question
up vote 9 down vote accepted

The [ is a command builtin, also known as test, and as all commands requires at least a space to separate it from other words in the command. [ is also available as a regular command in /usr/bin/[ or /usr/bin/test.

The presence of a final ] is instead a requirement of the command, when invoked as [, and the spaces around it are required as for every parameter of a command.

That said, in bash you should use the command [[, that has some avantages over [, like for example supporting && and || for logical operations, beside -a and -o.

Moreover, to do integer arithmetic operations and comparison between integers it is better to use arithmetic expansions $((math operations)), and the corresponding command ((math ops)).

With these observations, your script could be:


echo "Enter 1st number"
read n1
echo "Enter 2nd number"
read n2
echo "Multi is $((n1 * n2))"
if ((n1 > n2)); then
  echo "$n1 is bigger than $n2"
  echo "$n2 is bigger than $n1"

Remember to make it executable (chmod +x my-script), then execute it with ./my-script.

share|improve this answer
Just curious, is there any necessity besides convenience to make a script executable rather than calling bash As I understand it, they both translate to the same actions on the part of the shell, but I could be wrong. – Kris Harper Aug 18 '11 at 13:11
@root45: there is no difference that I know of. Also, the latter works also if is not marked as executable. But the user should not know how the developer write the application, he should just call it by name. In /usr/bin there are ELF binaries, perl, python, sh, bash scripts and also other type of applications. – enzotib Aug 18 '11 at 13:38

For bash conditional if statements, you need to have a whitespace right before and right after your condition. Yours should look like:

if [ $n1 -lt $n2 ]

instead of

if [$n1 -lt $n2]

Goofy, but that's the bash shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.