String length in ksh

Hi all,

I have tried the following simple code in ksh. (length.sh)

#! /usr/bin/ksh
var="xxxxxx0987890"
echo stringlength is ${#var}

but this gives me a error saying "length.sh: bad substitution"

Can some one please help me in resolving this.

Try command wc -c to count characters in the string.
Rgds.

That should work. What system on you on? What interactive shell are you using? What are the permissions on length.sh? What command line are you using to invoke length.sh?

I am using my school account remotely using ssh. Remaining of my scritps worked. but I dont know why this gives me an error. Will using the remote account cause restrictions in permissions...

The question still needs to be answered as to what shell you are using. The method you used to compute string length is correct for KSH.

What happens if /usr/bin/ksh is not present? It doesn't seem likely that it is since he stated that his remaining scripts do work. When I run sh on my system, I get the same error so it does appear that his default shell is sh and it does not support ${#var}.