Apologies if what I'm asking is stupid. That said, can someone help me out?
Pop!_OS based on Ubuntu 21.10 | Linux 5.15.8-76051508-generic | wayland display manager
karthik@cosmic:~$ read -p "enter" VAR
enterANything
karthik@cosmic:~$ echo $VAR
ANything
karthik@cosmic:~$ if [ "$VAR"=="Hello" ]
> then
> echo "True"
> fi
True
karthik@cosmic:~$
adding spaces make it work!
Regarding why bash works that way, I'll google it.
Thanks man. – karthik nair Jan 02 '22 at 09:57
[ ... ]
, given a single string between[
and]
, returns true if that string is non-empty. It's the same as[ -n string ]
, and"$VAR"=="Hello"
is a single non-empty string. – Kusalananda Jan 02 '22 at 11:34