[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Expanding undefined variables within a shell



Regid Ichira:
>
>   Within a shell, what is the difference between [ -n undefinedString ] and [ -n "$undefinedString" ] ?

The interesting difference is between $undefinedString and
"$undefinedString". The former resolves to literally nothing, not even
an empty string. When you use qoutes, you get an empty string. Using
quotes in this context prevents syntax errors.

In order to prevent such errors, you can also use bash's -u option (in
scripts: set -u). This makes bash abort immediately when it has to use
uninitialized variables. -e is also advisable under most circumstances.

J.
-- 
I count my partner's eyelashes.
[Agree]   [Disagree]
                 <http://www.slowlydownward.com/NODATA/data_enter2.html>

Attachment: signature.asc
Description: Digital signature


Reply to: