I'd make sure that the variable actually has a value right before you do the DID line.

Before the DID line, use: echo -a %fd

See if it outputs the value when it's a number. It is possible that wherever you're setting the variable is incorrect and the variable is not set when it's a number because of that part of the script. The DID line should be fine.