Check if variable is set in script

I want to check to see if a variable is set - and if not set it to something

ie. variable name test
I want to check if $test is set
then if there is nothing set against this currently - then set it to 0

Whats the best / shortest way of doing this in a script?

Initialize the variable to some value say 'x'.

var="x"

if(var ne "x") { the variable contains some value other than 'x' }
else { the variable is not changed }

Use ksh. ksh has shell builtin's to check for those conditions.

From man ksh under the Parameter sub-heading.

       Modifiers can be applied to the ${name} form of parameter substitution:

       ${name:-word}
              if  name  is set and not null, it is substituted, otherwise word
              is substituted.

       ${name:+word}
              if name is set and not  null,  word  is  substituted,  otherwise
              nothing is substituted.

       ${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.

       ${name:?word}
              if name is set and not null, it is substituted,  otherwise  word
              is  printed  on  standard error (preceded by name:) and an error
              occurs (normally causing termination of a shell script, function
              or  .-script).  If word is omitted the string ?parameter null or
              not set? is used instead.

       In the above modifiers, the : can be omitted, in which case the  condi-
       tions  only  depend on name being set (as opposed to set and not null).
       If word is needed, parameter, command, arithmetic and  tilde  substitu-
       tion are performed on it; if word is not needed, it is not evaluated.

Have a look at examples given in the orielly book Learning the Korn Shell

Vino

VAR=${VAR:=default_value}

if VAR is already set (and not null), will be reset with its own value; else will be set to "default_value". In your case, you can put 0 for this value.
Another less elegant but maybe more clear way is:

[ "$VAR" ] || VAR=default_value