hel hel - 1 year ago 63
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:

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download