<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Try if [ "X01" = "X${date}" ] then if $date is empty you still have "X".<br><br>Al<br><br><br><div>> Date: Wed, 20 Jul 2011 15:22:40 -0400<br>> From: ale-at-ale.org@unpopularminds.org<br>> To: ale@ale.org<br>> Subject: Re: [ale] Bash confusion<br>> <br>> On Wed, Jul 20, 2011 at 01:04:10PM -0400, Brian MacLeod wrote:<br>> > You are doing a string comparison here, so you should take the correct<br>> > precautions:<br>> > > if [ $date = "01" ];<br>> > should be like this:<br>> > if [ "01" = "$date" ];<br>> > Why?<br>> > If for some ungodly reason your variable ends up as null, the whole<br>> > statement (and function, etc) breaks if you have that null in front of<br>> > the equal sign. Flip that around and it "properly" evaluates even if<br>> > null. Otherwise you'll see things like "unary operator" and such.<br>> > The other thing is making sure you treat your variable as a string,<br>> > thus, quote it so that you are sure it isn't being further evaluated<br>> > and/or evaluated differently.<br>> <br>> Order is irrelevent; quoting the string protects against null values.<br>> <br>> if [ "$date" = "01" ]<br>> <br>> is safe, while<br>> <br>> if [ "01" = $date ]<br>> <br>> fails if $date is a null string.<br>> <br>> <br>> Regarding the original problem, as written, yes, it should work. But...<br>> <br>> Are there any commands between the date command and the test? There's no<br>> explicit path used to date - could it be executing a different version of<br>> date which is evaluating improperly? IOW, what are you telling us? ;)<br>> <br>> -L<br>> _______________________________________________<br>> Ale mailing list<br>> Ale@ale.org<br>> http://mail.ale.org/mailman/listinfo/ale<br>> See JOBS, ANNOUNCE and SCHOOLS lists at<br>> http://mail.ale.org/mailman/listinfo<br></div>                                            </div></body>
</html>