hel hel - 4 months ago 7
Linux Question

When does a variable add $ in bash

I'm recently learning bash and confused when a variable would add

$
. I find code like:

i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
i=`expr $i + 1`
done

Answer

The $ substitutes the variable. Writing $i will insert the value of i, no matter where you write it.

If you want to assign to the variable, that obviously makes no sense.