<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Tech-Recipes - Latest Comments in Bourne/bash shell scripts: string comparison</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><atom:link href="https://tech-recipes.disqus.com/bournebash_shell_scripts_string_comparison_bourne_shell_scripting_tech_recipes/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 06 May 2011 13:53:32 -0000</lastBuildDate><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-198494242</link><description>&lt;p&gt; I had the same exact problem and it drove me nutty batshiat-insane.  The problem:  you need a space before and after the = sign. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Daman Sternpak</dc:creator><pubDate>Fri, 06 May 2011 13:53:32 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-154694275</link><description>&lt;p&gt;== never works. bloody are you kidding by posting wrong things over here?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Man1</dc:creator><pubDate>Wed, 23 Feb 2011 11:48:48 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-153392988</link><description>&lt;p&gt;I do this by escaping less and greater sign, and it seems to work fine :&lt;/p&gt;&lt;p&gt;$&amp;gt; [ "a" \&amp;gt; "b" ]&lt;br&gt;$&amp;gt; echo $?&lt;br&gt;1&lt;br&gt;$&amp;gt; [ "c" \&amp;gt; "b" ]&lt;br&gt;$&amp;gt; echo $?&lt;br&gt;0&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Bermic2003</dc:creator><pubDate>Mon, 21 Feb 2011 09:50:31 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-129610845</link><description>&lt;p&gt;How can I compare two strings on less or greater? signs &amp;gt; and &amp;lt; treats as redirections!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tolya_kashuba</dc:creator><pubDate>Sat, 15 Jan 2011 22:46:10 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-98944236</link><description>&lt;p&gt;Thanks for the comments.  Somehow this article fell off our radar and I didn't realize we had an issue with it.  I really appreciate Martin for dropping me the email about the issue.  The original tutorial has been updated.  &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">qdideas</dc:creator><pubDate>Thu, 18 Nov 2010 14:27:15 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-79794364</link><description>&lt;p&gt;Wow, have you geeks ever thought about getting along?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Smudge</dc:creator><pubDate>Tue, 21 Sep 2010 15:46:09 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-55097341</link><description>&lt;p&gt;both the commands are not working, it throwing an error&lt;br&gt;./hello: [one=one]: not found&lt;/p&gt;&lt;p&gt;( var value 'one')&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Achu</dc:creator><pubDate>Mon, 07 Jun 2010 05:57:51 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-50678971</link><description>&lt;p&gt;you can compare two string variables using&lt;br&gt;if [ $var1 == $var2 ] &lt;br&gt;if [ $var1 = $var2 ]&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kousalya</dc:creator><pubDate>Mon, 17 May 2010 05:51:12 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-50678627</link><description>&lt;p&gt;you can compare two string variables using&lt;br&gt;if [ $var1 == $var2 ]&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kousalya</dc:creator><pubDate>Mon, 17 May 2010 05:42:10 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-45806691</link><description>&lt;p&gt;Can a variable be compared with an another variable eg : if [[ $var1 == $var2 ]]&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">hema</dc:creator><pubDate>Wed, 21 Apr 2010 08:40:47 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-23474113</link><description>&lt;p&gt;You're lying. That dosen't work.&lt;br&gt;test: 40: ==: unexpected operator&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">BhupinderSingh is a layer</dc:creator><pubDate>Wed, 18 Nov 2009 14:20:10 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-21001564</link><description>&lt;p&gt;The correct solution is here a year ago. It should be corrected in the article too, so one won't try those for 10 minutes before finding the answer here.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">netuddki</dc:creator><pubDate>Sun, 25 Oct 2009 19:59:53 -0000</pubDate></item><item><title>Re: Bourne/bash shell scripts: string comparison</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-8257877</link><description>&lt;p&gt;This is the method i curently to test if a string is empty:&lt;/p&gt;&lt;p&gt;if [ "X${VAR}" = "X" ]; then&lt;br&gt;          echo "Empty string"&lt;br&gt;fi&lt;/p&gt;&lt;p&gt;Testing for equality follows the same logic but without X.&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-7738156</link><description>&lt;p&gt;These examples don't work.&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-7561667</link><description>&lt;p&gt;if  [  "$var"  = "value" ]&lt;br&gt;then&lt;br&gt;echo not the same&lt;br&gt;fi&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-3222040</link><description>&lt;p&gt;i believe the $var needs to be in quotes, like so:&lt;/p&gt;&lt;p&gt;if [ -z "$var" ];then&lt;br&gt;echo null&lt;br&gt;fi&lt;/p&gt;&lt;p&gt;Best Regards,&lt;br&gt;Kibokina&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767131</link><description>&lt;p&gt;this can also be used to compare 2 strings&lt;/p&gt;&lt;p&gt;s1 = "as"&lt;br&gt;s2 = "bs"&lt;/p&gt;&lt;p&gt;if test $s1 == $s2&lt;br&gt;then &lt;br&gt;echo s1 and s2 are equal&lt;br&gt;fi&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767130</link><description>&lt;p&gt;the following syntax is wrong&lt;/p&gt;&lt;p&gt;if [ $var == "" ] ......&lt;/p&gt;&lt;p&gt;because if the variable $var is empty the test is  &lt;br&gt;if [ == "" ] and gives an error&lt;/p&gt;&lt;p&gt;you are obliged to quote the var :&lt;br&gt;if [ "$var" == "" ] ...&lt;/p&gt;&lt;p&gt;Sergio&lt;/p&gt;</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</title><link>http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/#comment-2767129</link><description>&lt;p&gt;Wouldn't the following be better?&lt;/p&gt;&lt;p&gt;if [ -z $var ];then&lt;br&gt;     echo null&lt;br&gt;fi&lt;/p&gt;</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>