> I'm wondering how would you test on the length of a string? Say to > test whether the variable $fname has the length longer than 2? > > I can use two (nested) expr command to do that or, one awk command > with echo: > > while `echo $fname | awk '{exit !(length() >2)}' `; do > > any other ways? thanks!
No external programs needed using ksh:
if [ ${#fname} -le 2 ] ; then print "shorter or equals 2" else print "longer than 2" fi
> How about bash? :-)
Normally for such simple examples ksh is quite close to bash syntax. It works if you do a s/print/printf/:
$ a=test $ if [ ${#a} -le 2 ]; then printf "shorter or equals 2"; else printf "longer than 2"; fi longer than 2
Best regards, Roberto Nibali, ratz