Need help on "while"

Hi,

I am a newbie to unix shell scripting. Can some one say what is wrong with the below code?

#!bin/sh
echo "Sleep and while do try"
i = "10"
while [ $i -gt 0 ]
do
  echo "$i seconds left"
  i= $ (expr $i -1)
  sleep 1
done

It gives me the following error message:
Sleep and while do try
a.sh: line 3: i: command not found
a.sh: line 7: syntax error near unexpected token `('
a.sh: line 7: ` i= $ (expr $i -1)'

Thanks in Advance!
Rajan.

This should work

#!/bin/sh
echo "Sleep and while do try"
i=10
while [ $i -gt 0 ]
do
  echo "$i seconds left"
  i=$(expr $i - 1)
  sleep 1
done
$

I see at least 4 errors there:

  1. The shebang line is missing a /, unless you always want to call an interpreter relative to your current path
  2. If you want to do variable assignments, there must be no whitespaces surrounding the assignment operator.
  3. The process substitution operator $() requires that there be no whitespace between the dollar sign and the opening bracket.
  4. expr requires that the operator and the operands are all separated by whitespace.

Hi,
Thanks folks.. It worked..:b: Thanks for pointing out and explaining the errors.. :o
Regards,
Rajan