<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: &amp;quot;if&amp;quot; statement usage in unix in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909848#M933265</link>
    <description>Paul -&lt;BR /&gt;A very good book for shell programming basics can be found at Barnes and Noble book stores or a subsidiary.&lt;BR /&gt;Look for UNIX Shell Programming&lt;BR /&gt;by Stephen G. Kochran and Patrick H. Wood.&lt;BR /&gt;&lt;BR /&gt;The if statement is same or similar across many platforms.&lt;BR /&gt;&lt;BR /&gt;ie. &lt;BR /&gt;if [ some condition ]&lt;BR /&gt;then&lt;BR /&gt;    do something&lt;BR /&gt;else&lt;BR /&gt;     do something else&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;There are many variations and ways of compounding and nesting.&lt;BR /&gt;&lt;BR /&gt;Fortran in '72, yeh, I remember doing that .... thanks for the reminder ....&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;dl</description>
    <pubDate>Thu, 20 Feb 2003 22:50:14 GMT</pubDate>
    <dc:creator>Dave La Mar</dc:creator>
    <dc:date>2003-02-20T22:50:14Z</dc:date>
    <item>
      <title>"if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909844#M933261</link>
      <description>This is the most embarassing question I've ever asked.  Is there a link to how to use the "if" statement in a script, or what the options like -en or -eq mean?&lt;BR /&gt;.&lt;BR /&gt;Is it used the same as in Fortran? (The last Fortran class I took was in 1972.)&lt;BR /&gt;.&lt;BR /&gt;Now that I've figured out how I give maximum points for the good suggestions. (I've been "prompted enough.)&lt;BR /&gt;.&lt;BR /&gt;Regards,&lt;BR /&gt;Paul Middleton &lt;BR /&gt;Lost, Lonely and Confused in Cleveland.&lt;BR /&gt;Think I'll visit my grandchildren tonight.</description>
      <pubDate>Thu, 20 Feb 2003 22:35:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909844#M933261</guid>
      <dc:creator>Paul Middleton</dc:creator>
      <dc:date>2003-02-20T22:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909845#M933262</link>
      <description>Do a &lt;BR /&gt;&lt;BR /&gt;# man sh&lt;BR /&gt;&lt;BR /&gt;or 'man whatever_shell_you_desire' and there is lots of information there.  I would also advise you get a book on shell programming.  I've got "UNIX shells by example" and I use it quite a bit.</description>
      <pubDate>Thu, 20 Feb 2003 22:41:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909845#M933262</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2003-02-20T22:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909846#M933263</link>
      <description>Hi Paul,&lt;BR /&gt;&lt;BR /&gt;The information you seek is in the man page for the shell you are using.&lt;BR /&gt;&lt;BR /&gt;One of these will probably get the info you want:&lt;BR /&gt;man sh-posix&lt;BR /&gt;man ksh&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;Tony</description>
      <pubDate>Thu, 20 Feb 2003 22:44:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909846#M933263</guid>
      <dc:creator>Tony Contratto</dc:creator>
      <dc:date>2003-02-20T22:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909847#M933264</link>
      <description>Oops...I just checked the 'man sh' page.  That ain't what you want.&lt;BR /&gt;&lt;BR /&gt;What you really want for the posix shell is:&lt;BR /&gt;&lt;BR /&gt;# man sh-posix&lt;BR /&gt;&lt;BR /&gt;For the ksh:&lt;BR /&gt;&lt;BR /&gt;# man ksh&lt;BR /&gt;&lt;BR /&gt;For the bourne shell&lt;BR /&gt;&lt;BR /&gt;# man sh-bourne&lt;BR /&gt;&lt;BR /&gt;For the csh:&lt;BR /&gt;&lt;BR /&gt;# man csh</description>
      <pubDate>Thu, 20 Feb 2003 22:45:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909847#M933264</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2003-02-20T22:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909848#M933265</link>
      <description>Paul -&lt;BR /&gt;A very good book for shell programming basics can be found at Barnes and Noble book stores or a subsidiary.&lt;BR /&gt;Look for UNIX Shell Programming&lt;BR /&gt;by Stephen G. Kochran and Patrick H. Wood.&lt;BR /&gt;&lt;BR /&gt;The if statement is same or similar across many platforms.&lt;BR /&gt;&lt;BR /&gt;ie. &lt;BR /&gt;if [ some condition ]&lt;BR /&gt;then&lt;BR /&gt;    do something&lt;BR /&gt;else&lt;BR /&gt;     do something else&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;There are many variations and ways of compounding and nesting.&lt;BR /&gt;&lt;BR /&gt;Fortran in '72, yeh, I remember doing that .... thanks for the reminder ....&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;dl</description>
      <pubDate>Thu, 20 Feb 2003 22:50:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909848#M933265</guid>
      <dc:creator>Dave La Mar</dc:creator>
      <dc:date>2003-02-20T22:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909849#M933266</link>
      <description>&lt;BR /&gt;A simple response:&lt;BR /&gt;&lt;BR /&gt;VAR1="text1"&lt;BR /&gt;VAR2=44&lt;BR /&gt;&lt;BR /&gt;if [ ${VAR1} = "text" -o ${VAR2} -ge 66 ]&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt;echo IN&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;echo OUT&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Maybe man test is better reference.&lt;BR /&gt;&lt;BR /&gt;Lots of examples in /sbin/rc0.d &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I will be here for a while...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Feb 2003 22:54:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909849#M933266</guid>
      <dc:creator>Carlos Fernandez Riera</dc:creator>
      <dc:date>2003-02-20T22:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909850#M933267</link>
      <description>"man test"  will explain the differences between -eq and =, etc., etc.....</description>
      <pubDate>Thu, 20 Feb 2003 23:09:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909850#M933267</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-02-20T23:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909851#M933268</link>
      <description>Here is the list of conditions from the ksh man page:&lt;BR /&gt;&lt;BR /&gt;Conditional Expressions.&lt;BR /&gt;      A conditional expression is used with the [[ compound command to test&lt;BR /&gt;      attributes of files and to compare strings.  Word splitting and file&lt;BR /&gt;      name generation are not performed on the words between [[ and ]].&lt;BR /&gt;      Each expression can be constructed from one or more of the following&lt;BR /&gt;      unary or binary expressions:&lt;BR /&gt;&lt;BR /&gt;           -a file             True if file exists.&lt;BR /&gt;&lt;BR /&gt;           -b file             True if file exists and is a block special&lt;BR /&gt;                               file.&lt;BR /&gt;           -c file             True if file exists and is a character&lt;BR /&gt;                               special file.&lt;BR /&gt;           -d file             True if file exists and is a directory.&lt;BR /&gt;           -f file             True if file exists and is an ordinary file.&lt;BR /&gt;           -g file             True if file exists and is has its setgid bit&lt;BR /&gt;                               set.&lt;BR /&gt;           -h file             True if file exists and is a a symbolic link.&lt;BR /&gt;           -k file             True if file exists and is has its sticky bit&lt;BR /&gt;                               set.&lt;BR /&gt;           -n string           True if length of string is non-zero.&lt;BR /&gt;           -o option           True if option named option is on.&lt;BR /&gt;           -p file             True if file exists and is a fifo special&lt;BR /&gt;                               file or a pipe.&lt;BR /&gt;           -r file             True if file exists and is readable by&lt;BR /&gt;                               current process.&lt;BR /&gt;           -s file             True if file exists and has size greater than&lt;BR /&gt;                               zero.&lt;BR /&gt;           -t fildes           True if file descriptor number fildes is open&lt;BR /&gt;                               and associated with a terminal device.&lt;BR /&gt;           -u file             True if file exists and is has its setuid bit&lt;BR /&gt;                               set.&lt;BR /&gt;           -w file             True if file exists and is writable by&lt;BR /&gt;                               current process.&lt;BR /&gt;           -x file             True if file exists and is executable by&lt;BR /&gt;                               current process.  If file exists and is a&lt;BR /&gt;                               directory, the current process has permission&lt;BR /&gt;                               to search in the directory.&lt;BR /&gt;           -z string           True if length of string is zero.  -L file&lt;BR /&gt;                               True if file exists and is a symbolic link.&lt;BR /&gt;           -O file             True if file exists and is owned by the&lt;BR /&gt;                               effective user ID of this process.&lt;BR /&gt;           -G file             True if file exists and its group matches the&lt;BR /&gt;                               effective group ID of this process.&lt;BR /&gt;           -S file             True if file exists and is a socket.&lt;BR /&gt;           file1 -nt file2     True if file1 exists and is newer than file2.&lt;BR /&gt;           file1 -ot file2     True if file1 exists and is older than file2.&lt;BR /&gt;           file1 -ef file2     True if file1 and file2 exist and refer to&lt;BR /&gt;                               the same file.&lt;BR /&gt;           string = pattern    True if string matches pattern.&lt;BR /&gt;           string != pattern   True if string does not match pattern.&lt;BR /&gt;           string1 &amp;lt; string2   True if string1 comes before string2 based on&lt;BR /&gt;                               ASCII value of their characters.&lt;BR /&gt;           string1 &amp;gt; string2   True if string1 comes after string2 based on&lt;BR /&gt;                               ASCII value of their characters.&lt;BR /&gt;           exp1 -eq exp2       True if exp1 is equal to exp2.&lt;BR /&gt;           exp1 -ne exp2       True if exp1 is not equal to exp2.&lt;BR /&gt;           exp1 -lt exp2       True if exp1 is less than exp2.&lt;BR /&gt;           exp1 -gt exp2       True if exp1 is greater than exp2.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How bout an amusing example:&lt;BR /&gt;&lt;BR /&gt;if [ -s $FRIDGE} ]&lt;BR /&gt;then /usr/local/bin/different_fridge&lt;BR /&gt;else&lt;BR /&gt;echo "Dear I'm off the nearest bar!"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Michael</description>
      <pubDate>Thu, 20 Feb 2003 23:15:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909851#M933268</guid>
      <dc:creator>Michael Tully</dc:creator>
      <dc:date>2003-02-20T23:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909852#M933269</link>
      <description>You might want to take a look here. Yeah I know is it for Solaris, but ksh is the same everywhere. Isn't it? Well close anyway.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.bolthole.com/solaris/ksh.html" target="_blank"&gt;http://www.bolthole.com/solaris/ksh.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck,&lt;BR /&gt;John</description>
      <pubDate>Thu, 20 Feb 2003 23:22:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909852#M933269</guid>
      <dc:creator>John Dvorchak</dc:creator>
      <dc:date>2003-02-20T23:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909853#M933270</link>
      <description>&lt;BR /&gt;Bear in mind that you should really learn one if and stick with it. The '[ ]' style if calls the external command test while the '[[ ]]' style command is internal to the shell BUT the syntax is a little different.&lt;BR /&gt;&lt;BR /&gt;if [ ${A} -le 5 -a ${B} -gt 10 ]&lt;BR /&gt;  then&lt;BR /&gt;     echo "Do something"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;becomes&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ ${A} -le 5 &amp;amp;&amp;amp; ${B} -gt 10 ]&lt;BR /&gt;  then&lt;BR /&gt;     echo "Do something"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;Note : AND -a becomes &amp;amp;&amp;amp; and&lt;BR /&gt;OR -o becomes ||.&lt;BR /&gt;&lt;BR /&gt;NOTE: The space between the comparand and the brackets is REQUIRED.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Feb 2003 23:31:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909853#M933270</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-02-20T23:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909854#M933271</link>
      <description>Hey Michael...&lt;BR /&gt;&lt;BR /&gt;I know you Ozzers are a different lot mate, but that if statement should be&lt;BR /&gt;&lt;BR /&gt;if&lt;BR /&gt;then&lt;BR /&gt;else&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Or is it...&lt;BR /&gt;&lt;BR /&gt;for&lt;BR /&gt;do&lt;BR /&gt;fe&lt;BR /&gt;fi&lt;BR /&gt;fo&lt;BR /&gt;fum&lt;BR /&gt;&lt;BR /&gt;Cheers buddy,&lt;BR /&gt;Jeff (Who sure wishes he was down under)</description>
      <pubDate>Fri, 21 Feb 2003 00:13:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909854#M933271</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2003-02-21T00:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909855#M933272</link>
      <description>Looks like the old fat finger syndrome....&lt;BR /&gt;&lt;BR /&gt;if [ -s $FRIDGE} ] &lt;BR /&gt;then /usr/local/bin/different_fridge &lt;BR /&gt;else &lt;BR /&gt;echo "Dear I'm off the nearest bar!" &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Perhaps it's either too much coffee and not enough beer .... 11:25AM .... bring on Friday lunch!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Feb 2003 00:25:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909855#M933272</guid>
      <dc:creator>Michael Tully</dc:creator>
      <dc:date>2003-02-21T00:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909856#M933273</link>
      <description>I'll second the motion on the Kochan and Wood book.  Mine already fell apart once from use, and its about to happen again.  &lt;BR /&gt;&lt;BR /&gt;Unlike some of the others, I come from a non technical background (sales).  So I understand you confusion about the 'if' command.  Here's a primer:&lt;BR /&gt;if &lt;SOMETHING&gt;&lt;BR /&gt;then&lt;BR /&gt;     do something&lt;BR /&gt;else&lt;BR /&gt;     do something else&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I almost always use 'if' with 'test'.  The test command is interesting when used with the 'if' command.  Do a man on test to find all the options, but I use the -f the -eq and the = options all the time.  There are differences between -eq and =.  The = compares strings, and the -eq compares numeric values.  &lt;BR /&gt;&lt;BR /&gt;It also really, really helps to know how, when and where to use quotes, and what kind to use.  The Kochan &amp;amp; Wood book has a whole chapter on this.  &lt;BR /&gt;&lt;BR /&gt;I've attached a fully documented and commented script that uses Netbackup commands to create a report.  Forget the Netbackup commands and look at the way the if/then statements are used.  There is also a simple looping structure within the main if/then statement.  &lt;BR /&gt;&lt;BR /&gt;Feel free to write me with any questions: cvail "at" ercot dot com.  &lt;BR /&gt;&lt;BR /&gt;Chris&lt;/SOMETHING&gt;</description>
      <pubDate>Fri, 21 Feb 2003 00:32:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909856#M933273</guid>
      <dc:creator>Chris Vail</dc:creator>
      <dc:date>2003-02-21T00:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909857#M933274</link>
      <description>Gentlemen,&lt;BR /&gt;Thanks for the information.  Sometimes you do learn one form of an if statement, then you need to change the way if works, and you have a massive brain fart.&lt;BR /&gt;.&lt;BR /&gt;The list of conditions is very useful and I'm looking into the man pages for sh and ksh now.&lt;BR /&gt;.&lt;BR /&gt;Again, thanks for all the help.&lt;BR /&gt;.&lt;BR /&gt;Paul Middleton</description>
      <pubDate>Fri, 21 Feb 2003 13:41:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909857#M933274</guid>
      <dc:creator>Paul Middleton</dc:creator>
      <dc:date>2003-02-21T13:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909858#M933275</link>
      <description>Paul,&lt;BR /&gt;&lt;BR /&gt;I scanned the messages pretty quickly, but did not see 'test' mentioned.  Do a man on 'test' for more info on the different options available for the 'if' construct.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Mark</description>
      <pubDate>Fri, 21 Feb 2003 14:48:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909858#M933275</guid>
      <dc:creator>Mark Ellzey</dc:creator>
      <dc:date>2003-02-21T14:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: "if" statement usage in unix</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909859#M933276</link>
      <description>The '[ ...'] construct is an alias for the&lt;BR /&gt;command 'test', as someone else noted.&lt;BR /&gt;However, I generally avoid '[ ... ]' / 'test'&lt;BR /&gt;because it doesn't handle empty&lt;BR /&gt;arguments very well.  The '[[ ... ]]'&lt;BR /&gt;operator is better behaved.  See&lt;BR /&gt;the man page for ksh or sh-posix&lt;BR /&gt;for details on '[[ ... ]]'&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;foo=""&lt;BR /&gt;if [ -n $foo ]&lt;BR /&gt;then&lt;BR /&gt;  echo foo is set&lt;BR /&gt;else&lt;BR /&gt;  echo foo is not set&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Because "$foo" evaluates to nothing,&lt;BR /&gt;"-n $foo" evaluates to "-n", which causes&lt;BR /&gt;the warning:&lt;BR /&gt;&lt;BR /&gt;test: Specify a parameter with this command.&lt;BR /&gt;&lt;BR /&gt;You have to put double quotes around $foo in&lt;BR /&gt;this example.  The '[[ ... ]]' operator does not&lt;BR /&gt;have this problem.&lt;BR /&gt;&lt;BR /&gt;In old scripts, you'll sometimes see people&lt;BR /&gt;do this to get around the problem:&lt;BR /&gt;&lt;BR /&gt;if [ X"$foo" = Xsomestring ]&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Feb 2003 19:14:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/quot-if-quot-statement-usage-in-unix/m-p/2909859#M933276</guid>
      <dc:creator>Gregory Fruth</dc:creator>
      <dc:date>2003-02-21T19:14:38Z</dc:date>
    </item>
  </channel>
</rss>

