I use this bash code to test whether two strings are equal, but the result is not as what I exptect. I have used ""
to wrap two strings and used [[]]
rather than []
in if
condition, but still failed. Where did I do wrong? Thanks in advance.
#!/bin/bash
touch a.txt b.txt
date -r a.txt +%y-%m-%d > b.txt
A="$(cat b.txt)"
B="$(date -r a.txt +%y-%m-%d)"
if [["$A" == "$B"]]
then
echo "equal"
else
echo "not equal"
fi
Error is listed below.
➜ ~ chmod a+x test.sh
➜ ~ ./test.sh
./test.sh: line 6: [[22-10-13: command not found
not equal