[Top][All Lists]

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

Re: [3.0.13] declare -a a=('$0')

From: Chet Ramey
Subject: Re: [3.0.13] declare -a a=('$0')
Date: Mon, 13 Sep 2004 16:46:30 -0400

> declare seems to evaluate its arguments:

It does.  The process is actually very regular.

Assignment statements (at least compound assignment statements) appearing
as arguments to `assignment builtins' are parsed specially -- as a single
word.  The word becomes one of the arguments to `declare', but marked as
an assignment.

Each argument to declare is expanded.  The words marked as assignments
(since `declare' is an `assignment builtin') are expanded exactly as
assignments preceding commands.

When declare is run, it re-parses the arguments that appear to be compound
assignments.  It does the expansion, because at this point there's no way
to tell whether or not the original assignment was quoted.

declare has to do some reparsing, since it only gets a single argument and
has to somehow split it and understand [index]=value.  It uses exactly the
same code as compound assignments preceding commands.

If you want to avoid this sort of double evaluation, use separate compound
assignment statements.

One reason to let declare do this is to avoid the files=(*) problem
you beat me up about so heavily earlier.  If you let the normal
argument expansion process do the work, you'll end up with arguments
like [index]=arg if there are files with names of that form, which
will be handled by assigning to files[index].  If you quote the `*' and
let declare do the job, you can avoid it.


``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Chet Ramey, ITS, CWRU    address@hidden    http://tiswww.tis.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]