I have this code:
#!/bin/bash
CMDA=$(curl -sI website.com/example.txt | grep Content-Length)
CMDB=$(curl -sI website.com/example.txt | grep Content-Length)
if [ "CMDA" == "CMDB" ];then
echo "equal";
else
echo "not equal";
fi
with this output
root@abcd:/var/www/html# bash ayy.sh
not equal
which should be "equal" instead of "not equal". What did I do wrong?
Thnaks
You forgot the $ for the variables CMDA and CMDB there. This is what you need:
if [ "$CMDA" = "$CMDB" ]; then
I also changed the == operator to =,
because man test only mentions =,
and not ==.
Also, you have some redundant semicolons. The whole thing a bit cleaner:
if [ "$CMDA" = "$CMDB" ]; then
echo "equal"
else
echo "not equal"
fi
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