Getting "command not found" error while comparing two strings in Bash

EpsilonAlpha picture EpsilonAlpha · Nov 1, 2013 · Viewed 73.7k times · Source

My whole Script is currently this:

#!/bin/sh   
clear;   
blanko="";   
# Dummy-Variablen
variable=Testvariable;   
if [[$variable == $blanko]];
then   
  echo "Nichts da!"   
else   
  echo $variable   
fi

and if i enter

TestSelect.sh

i get

/usr/bin/TestSelect.sh: line 6: [[Testvariable: command not found   
Testvariable

how can i fix this?

Answer

anubhava picture anubhava · Nov 1, 2013

This is problem:

if [[$variable == $blanko]];

Spaces are required inside square brackets, use it like this:

[[ "$variable" == "$blanko" ]] && echo "Nichts da!" || echo "$variable"