Messed up script

| 0 Comments

Wasted nearly two hours trying to figure out why some simple bash script of mine wasn't working.

#!/bin/sh

HOSTNAME=$(hostname)
echo HOSTNAME=$HOSTNAME

if [ "$HOSTNAME" == "kiffins-laptop" ]; then echo "This is Kiffin's laptop"
elif [ "$HOSTNAME" == "georges-laptop" ]; then echo "This is George's laptop"
else
    echo 'Unknown hostname (exit)'
    exit 1
fi
echo "Success"
exit 0

Looks perfectly valid to me, so how come when I run the damned script I get the following error messages?

HOSTNAME=laptop
[: 11: laptop: unexpected operator
[: 11: laptop: unexpected operator
Unknown hostname (exit)

Need a hint?

Leave a comment

Recent Entries

Clojure one-liner
I am convinced that the new programming language called Clojure has alot of potential and if successful will fundamentally ... »
Trusting yourself
An excellent book that I've been reading is called Management 3.0 by Jurgen Appelo. The book has all kinds ... »
Remembering and then forgetting
There is that last fleeting moment right before you fall asleep when your mind empties of all thought and ... »
Zuma
Being stuck in the middle of a huge traffic jam just south of Amsterdam is no fun, especially when ... »
Running in the cold
Most people of sound mind would find it extremely difficult to understand that inner urge of mine which keeps ... »