I have a string, like this:
DayOfWeek=$(date +%A|tr -d '\n')
echo $DayOfWeek
Montag
I wish to compare the result of the command with a string. Just like this:
[ $DayOfWeek == "Monday" ] && echo True
But the result was anytime false.
Here some more attempts:
[ "$DayOfWeek" == "Monday" ] && echo True
[ $(date +%A|tr -d '\n') == "Monday" ] && echo True
[ $(date +%A|tr -d '\n') == "Monday" ] && echo True
[ $(date +%A|tr -d '\n') == 'Monday' ] && echo True
[ "$(printf "%s" "$DayOfWeek")" == "Monday" ] && echo True
[ "$(date +%A|tr -d '\n')" == 'Monday' ] && echo True
[[ $(date +%A|tr -d '\n') == 'Monday' ]] && echo True
[[ $(date +%A|tr -d '\n') == "Monday" ]] && echo True
In the end following is working:
[[ $(date +%A|tr -d '\n') == $(echo -n "Montag") ]] && echo True
Can someone explain this behavior of bash to me? The used bash is version 4.4.19.
best regards, akendo