[PLUG] How to test a string against a blank string in shell script
mahaveer darade
mah.darade at gmail.com
Fri Mar 26 09:34:14 IST 2010
to compare a string with blank string u can do something like
if [ "X${str1}" == "X${str2}" ]
here even if either of string is blank it won't give any syntax error.
~md
On Thu, Mar 25, 2010 at 10:09 PM, Gaurav Pant <gauravggs at gmail.com> wrote:
> Hi
>
> On Thu, Mar 25, 2010 at 5:43 PM, Shreerang Patwardhan
> <patwardhan.shreerang at gmail.com> wrote:
> > Hey all,
> > I found the solution to my problem which was as stated below:
> >
> > How do we compare a string with a blank string.
> > Example: String 1 = test
> > String 2 =
>
> to test for a blank string in shell scripting use
> -z string returns True if the length of string is zero.
> -n string True if the length of string is non-zero.
>
> if you want to consider a string containing all spaces check it with
> grep!!!
>
> regards
> Dexter
>
> _______________________________________
> Pune GNU/Linux Users Group Mailing List
>
--
Thanks,
Mahaveer
+91 9052000707
More information about the Plug-mail
mailing list