Re: Should integer variables be quoted?

Lao Ming <laomingliu@xxxxxxxxx> writes:

I've often seen the refrain about shell variables
always being quoted (which I agree with)
but I've also found instances where they
cannot (and probably should not) be quoted.
An example of this is a case statement
or an if statement where an integer is
being compared. Doesn't quoting an integer
make it a string and thus break the compare?

You are confusing compiler quoting with shell quuoting.

When you quote somethign in a compiler, you tell the software that you
are providing a string. The shell doesn't work that way.

Think of shell "quoting" as a flag, per character, to tell the shell if it's
a special character (like '*' OR '?' OR '$') or a character that the
shell treats as a plain character.

So when you quote something, it tells the shell to consider the
characters as typed

all do the same thing.

Use the echo command to experiment.

echo a*b

will list files that start with a and end with b, because the * is
considered a special character that the shell "globs" into a list of
files mathcing the pattern.

echo "a*b"
treats '*' as a plain character with no special properties (like a and b)