
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.thelinuxwiki.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Bash_null_check</id>
		<title>Bash null check - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Bash_null_check"/>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Bash_null_check&amp;action=history"/>
		<updated>2026-04-29T02:46:15Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.5</generator>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Bash_null_check&amp;diff=78&amp;oldid=prev</id>
		<title>Nighthawk: Pushed from thelinuxwiki.com.</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Bash_null_check&amp;diff=78&amp;oldid=prev"/>
				<updated>2013-02-25T19:01:57Z</updated>
		
		<summary type="html">&lt;p&gt;Pushed from thelinuxwiki.com.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The -n operator checks whether the string is not null. Effectively, this will return true for every case except where the string contains no characters. ie:&lt;br /&gt;
&lt;br /&gt;
 VAR=&amp;quot;hello&amp;quot;&lt;br /&gt;
 if [ -n &amp;quot;$VAR&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;VAR is not empty&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Similarly, the -z operator checks whether the string is null. ie:&lt;br /&gt;
&lt;br /&gt;
 VAR=&amp;quot;&amp;quot;&lt;br /&gt;
 if [ -z &amp;quot;$VAR&amp;quot; ]; then&lt;br /&gt;
    echo &amp;quot;VAR is empty&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
Note the spaces around the square brackets. Bash will complain if the spaces are not there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''example using null check to see if a drive is mounted'''&lt;br /&gt;
 volume=&amp;quot;toshibaHD&amp;quot;&lt;br /&gt;
 check=$(mount|grep $volume)    &lt;br /&gt;
 if [ -n &amp;quot;$check&amp;quot; ]&lt;br /&gt;
 then&lt;br /&gt;
   echo &amp;quot;\$check is NOT null&amp;quot;&lt;br /&gt;
 else&lt;br /&gt;
  echo &amp;quot;\$check IS null&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
[[category:bash]]&lt;/div&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	</feed>