I am missing something fundamental concerning either the bash's if construct/operators or string comparison. Consider the following script:
#!/bin/bash
baseSystem="testdir1"
testme="NA"
if [ "$baseSystem"=="$testme" ]; then
echo "In error case"
fi
if [ "$baseSystem"!="$testme" ]; then
echo "In error case"
fi
I get:
In error case
In error case
So it enters each case even though they should be mututally exclusive. Any help is appreciated.
bash
happens to be somewhat particular about spaces.
Add spaces around the operators:
if [ "$baseSystem" == "$testme" ]; then
...
if [ "$baseSystem" != "$testme" ]; then
The following are not equivalent:
[ "$a"="$b" ]
[ "$a" = "$b" ]
Your first test is essentially the same as saying if [ "testdir1==NA" ]; then
which would always be true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With