Re: how to check the length of a variable in ksh?

From: Clifton, Pablo (Pablo.Clifton@BCBSFL.COM)
Date: Thu Nov 21 2002 - 14:28:44 EST


Thanks to ALL for the help- I'd been stumped for about a week and
I thought I was going to have to write a C program :)

-pablo

--
Pablo Clifton
UNIX Tech Services
-----Original Message-----
From: cbaker@GOODYEAR.COM [mailto:cbaker@GOODYEAR.COM]
Sent: Thursday, November 21, 2002 1:53 PM
To: aix-l@Princeton.EDU
Subject: Re: how to check the length of a variable in ksh?
Bill,
Your answer is pretty good, and is the way I used, but:
1) You need to put double quotes about the $i
     if (( $(expr "$i" : ".*") > 5 ))
because the variable could contain imbedded spaces, null, etc.
2)After seeing Craig's solution, (one that I never knew about)
     if (( ${#variable} > 5 ))
I think I like that even better.
Christopher M. Baker
Senior Technical Support Analyst
DSE/TCO
Goodyear Tire and Rubber Company
=================================================
Contains Confidential and/or Proprietary Information.
May not be copied or disseminated without the expressed
written consent of The Goodyear Tire & Rubber Company.
=================================================
                    Bill Thompson
                    <bill.thompson@GOO        To:     aix-l@Princeton.EDU
                    DYEAR.COM>                cc:
                    Sent by: IBM AIX          Subject:     Re: how to check
the length of a variable in ksh?
                    Discussion List
                    <aix-l@Princeton.E
                    DU>
                    11/21/2002 12:50
                    PM
                    Please respond to
                    IBM AIX Discussion
                    List
if (( $(expr $i : ".*") > 5 ))
then
        do something
fi
Bill Thompson
Sr UNIX Systems Administrator
The Goodyear Tire & Rubber Co.
Contains Confidential and/or Proprietary Information
May Not Be Copied or Disseminated Without Express Consent of The Goodyear
Tire & Rubber Company.
AIX-L Archives: http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2
----- Original Message -----
From: "Clifton, Pablo" <Pablo.Clifton@BCBSFL.COM>
Newsgroups: bit.listserv.aix-l
To: <aix-l@Princeton.EDU>
Sent: Thursday, November 21, 2002 12:01 PM
Subject: how to check the length of a variable in ksh?
> Hi-
>
> Anyone know how I can check in a korn shell script:
>
>         if [[    length of variable $i is > 5 characters        ]]
>         then
>                 do something
>         fi
>
> thanks,
> -pablo
>
> --
> Pablo Clifton
> UNIX Tech Services
>
>
>
>
> Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
> affiliate companies are not responsible for errors or omissions in this
e-mail message. Any personal comments made in this e-mail do not reflect
the views of Blue Cross Blue Shield of Florida, Inc.
Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc.


This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:22 EDT