How to modify the variable

I have a directory name stored in a variable. Does anyone have a piece of code which checks if this stored directory name ends up with the "/" and if it is missing adds it to the same variable. for example I might have
A=/bb/data or A=/bb/data/
which needs to be A=/bb/data/ for sure
thanks a lot to all for help -A

You did not specify what shell you are using. However, the following works for ksh93 - assuming A contains the directory variable.

[[ ${A:${#A}-1} != '/' ]] && A="${A}/"

Thanks a lot, I am using ksh in my scripting, will this code work?

It depends on which version of ksh you are using. There are 3 major versions of ksh in general use - ksh88, pdksh and ksh93.

Another one:

case $A in */);;*)A=$A/;;esac

I am using ksh88
@(#)Version M-11/16/88i

The above command fails with the following output
op - sundev1 $ [[ ${A:${#A}-1} != '/' ]] && A="${A}/"
ksh: ${A:${#A}-1}: bad substitution

Not sure how to fix it... Any idea? Thanks a lot in advance -A