if condition

Hi friends, :slight_smile:
In a shell script i found the following if condition.
echo -n "Which version of $1 do you want to restore ('0' to quit)? [1] : "
read desired
if [ ${desired:=1} -ge $index ] ; then
echo "$0: Restore canceled by user: index value too big." >&2
exit 1
fi
Can anybodyof you tell me how the condition
if [ ${desired:=1} -ge $index ] works.

cheers
RRK

Tha man says,

    ${name:=word}
              if  name is set and not null, it is substituted, otherwise it is
              assigned word and the resulting value of name is substituted.

The folllowing demonstrates the usage, Try running the program with and without providing the value at the prompt.

#!/bin/ksh
let index=5
print "Enter the value of $1:\c"
read val
echo "The value input was: $val"
if [ ${val:=1} -ge $index ] ;then
 echo "Cancelled index too big "
 echo "The value inside the if:  $val"
 exit 1
fi
 echo "The value at exit: $val"

Please let us know if this doesnot clarify.

Thanks
Nagarajan Ganesan.