<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Tech-Recipes - Latest Comments in Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><language>en</language><lastBuildDate>Thu, 16 Apr 2009 08:35:45 -0000</lastBuildDate><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-8257877</link><description>This is the method i curently to test if a string is empty:&lt;br&gt;&lt;br&gt;if [ "X${VAR}" = "X" ]; then&lt;br&gt;          echo "Empty string"&lt;br&gt;fi&lt;br&gt;&lt;br&gt;Testing for equality follows the same logic but without X.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Florin</dc:creator><pubDate>Thu, 16 Apr 2009 08:35:45 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-7738156</link><description>These examples don't work.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">asd</dc:creator><pubDate>Thu, 02 Apr 2009 04:58:39 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-7561667</link><description>if  [  "$var"  = "value" ]&lt;br&gt;then&lt;br&gt;echo not the same&lt;br&gt;fi</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bhargav</dc:creator><pubDate>Fri, 27 Mar 2009 13:15:41 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-3222040</link><description>i believe the $var needs to be in quotes, like so:&lt;br&gt;&lt;br&gt;if [ -z "$var" ];then&lt;br&gt;echo null&lt;br&gt;fi&lt;br&gt;&lt;br&gt;Best Regards,&lt;br&gt;Kibokina</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Tue, 21 Oct 2008 23:38:39 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767131</link><description>this can also be used to compare 2 strings&lt;br&gt;&lt;br&gt;s1 = "as"&lt;br&gt;s2 = "bs"&lt;br&gt;&lt;br&gt;if test $s1 == $s2&lt;br&gt;then &lt;br&gt;echo s1 and s2 are equal&lt;br&gt;fi</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">BhupinderSingh</dc:creator><pubDate>Fri, 10 Jun 2005 00:43:20 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767130</link><description>the following syntax is wrong &lt;br&gt;&lt;br&gt;if [ $var == "" ] ......&lt;br&gt;&lt;br&gt;because if the variable $var is empty the test is  &lt;br&gt;if [ == "" ] and gives an error &lt;br&gt;&lt;br&gt;you are obliged to quote the var :&lt;br&gt;if [ "$var" == "" ] ... &lt;br&gt;&lt;br&gt;&lt;br&gt;Sergio</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">guest</dc:creator><pubDate>Thu, 04 Mar 2004 19:35:13 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison | Bourne shell scripting | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767129</link><description>Wouldn't the following be better?&lt;br&gt;&lt;br&gt;if [ -z $var ];then&lt;br&gt;     echo null&lt;br&gt;fi</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Sun, 01 Feb 2004 10:47:19 -0000</pubDate></item></channel></rss>