Does anyone know which command I can use to find out the length of a string held within a variable?
"length=${#variable}" works in ksh and bash.
For lower voltage shells, 'echo "$variable" | wc -c' comes close, but it includes the newline character so you need to subtract one.
length=`expr length "$variable"` used to work, but some modern versions of expr no longer support it.
Thank you very much for your help
so how can i get the actual length of the word?
how to subtract 1 from the 'echo "$variable" | wc -c'
?
This was done on a Dynix/ptx 4.4.8 OS. (the NUMA-Q system formerly known as Sequent)
off_count=`echo "$variable" | wc -c`
or
off_count=$(echo "$variable" |wc -c)
Then the next two commands will calculate and display the result.
(( ok_count = $off_count - 1 ))
echo $ok_count
try ...
let count=`$variable | wc -c`-1
echo $count