I'm trying to debug an existing program and found an if condition without $ symbol prefixed to it.
Values are:
dt_val=1234
prev_dt_val=1234
If condition goes like:
if [ dt_val -eq prev_dt_val ]
then
echo "Equal"
else
echo "Not equal"
fi
Result:
Equal
Anyone throw some light on how the condition is working fine without a $ symbol?
Shouldn't that be..?
[ $dt_val -eq $prev_dt_val ]
The same condition fails when comparing string values. Does that mean, this condition does not require a $ symbol for number?
Additional info:
Comparing Strings with == as suggested:
dt_val="abcd"
prev_dt_val="abcd"
if [ dt_val == prev_dt_val ]
> then
> echo Equal
> else
> echo Not equal
> fi
Not equal
Shell Info:
echo $SHELL
/usr/bin/ksh
Version M-11/16/88f
Wondering why there's no error either.
$[[instead of[-- unix.stackexchange.com/q/244685/117549-eqwould be wrong for strings (use=or!=for strings).[is a built-in command, and it may treat the-eqtest as a proper arithmetic context.$is not needed on variables in an arithmetic context.