Archive

Monthly Archives: May 2013

Help is available in the net.

http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/comparison-ops.html
http://www.ibm.com/developerworks/library/l-bash-test/index.html

As you see, one can spend quite a time on comparison of unstructured objects. But dont expect you are done with it by studying those pages.

For example one might expect

if [[ "Aha" ==   *   ]]
if [[   *   == "Aha" ]]

to be equivalent. But then things would be too simple. Note that this is not about expansion.

Advertisements

Speaking of if, which of the following lines are ok?

if [ "aha"=="aha" ]
if [ "aha" == "aha" ]
if [[ "aha" == "aha" ]]
if [[ "aha" = "aha" ]]
if [["aha" == "aha"]]
if [ ["aha" == "aha"] ]
if [ [ "aha" == "aha" ] ]

Some background: In complex software assemblies a processing pattern named ‘condition’ turned out to be highly valuable and bash fully supports this concept by means of the ‘if’-structure. It is not designed for beginners. Though, provided a certain expertise, the deployment of the structure can be realized on short notice.

correct?

if [[ "aha"=="aha" ]] ;
then 
    echo "yes" 
fi;

Hint: There are positions where you can put semicolons or white spaces and others where you cant. You have to think about it? This means that bash is a fail.