[prev in list] [next in list] [prev in thread] [next in thread]
List: hpux-admin
Subject: [HPADM] testing for blanks in a variable
From: Jason Isaac <JasonIsaac () HamptonAffiliates ! com>
Date: 2002-02-28 17:41:25
[Download RAW message or body]
I need to check and see if a variable contains all blanks/whitespace by
comparing the value of the variable to a character class..
I found one method that worked but it seems a bit clumsy.
This works:
If [ "`echo ${ADDR1} | tr -d '[:space:]'` = "" ]
Then
Echo "ADDR1 is blank."
fi
I thought that I could do something like:
If [ "${ADDR1}" = [[:space:]] ]
Then
Echo "ADDR1 is blank."
fi
but this fails pretty thoroughly.
Was I completely wrong about being able to use a character class in a
comparison?
I am running HP-UX 11.0.
Thanks,
Jason
Jason Isaac
Unix System Administrator
Hampton Lumber Sales DID: 503-203-6516
jasonisaac@hamptonaffiliates.com Pager: (503)-237-6080
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>testing for blanks in a variable</TITLE>
</HEAD>
<BODY>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">I need to check and see if a \
variable contains all blanks/whitespace</FONT><FONT COLOR="#000000" SIZE=2 \
FACE="Arial"> by comparing the value of the variable to a character \
class.</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">.</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">I found one method that \
worked but it seems a bit clumsy. <BR> This works: </FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">If</FONT> <FONT \
COLOR="#000000" SIZE=2 FACE="Arial">[ "`echo ${ADDR1} | tr -d '[:space:]'` = "" \
]</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Then</FONT></P>
<P ALIGN=LEFT> <FONT COLOR="#000000" SIZE=2 \
FACE="Arial">Echo "ADDR1 is blank."</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">fi</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">I thought</FONT> <FONT \
COLOR="#000000" SIZE=2 FACE="Arial">that I could do something like:</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">If [ "${ADDR1}</FONT><FONT \
COLOR="#000000" SIZE=2 FACE="Arial">"</FONT><FONT COLOR="#000000" SIZE=2 \
FACE="Arial"> = [[:space:]] ]</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Then</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Echo "ADDR1 is \
blank."</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">fi</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">but this fails pretty \
thoroughly.</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Was I completely wrong about \
being able to use a character class in a comparison?</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">I am running \
HP-UX</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial"> 11.0.</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Thanks,</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Jason</FONT></P>
<BR>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Jason Isaac</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Unix System \
Administrator</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 FACE="Arial">Hampton Lumber \
Sales \
\
DID: 503-203-6516</FONT></P>
<P ALIGN=LEFT><FONT COLOR="#000000" SIZE=2 \
FACE="Arial">jasonisaac@hamptonaffiliates.com \
Pager: (503)-237-6080</FONT></P>
</BODY>
</HTML>
--
---> Please post QUESTIONS and SUMMARIES only!! <---
To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
Name: hpux-admin@dutchworks.nl Owner: owner-hpux-admin@dutchworks.nl
Archives: ftp.dutchworks.nl/pub/digests/hpux-admin (FTP, browse only)
http://www.dutchworks.nl/htbin/hpsysadmin (Web, browse & search)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic