bug-bash
[Top][All Lists]
Advanced

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

Re: ${var:+foo "$empty"}


From: Chet Ramey
Subject: Re: ${var:+foo "$empty"}
Date: Mon, 7 Feb 2005 17:21:44 -0500

> There's still one obscur thing:
> 
> $ a() { echo $#; }
> $ a=
> $ a ${a+"$a"}
> 1
> $ a ${a+ "$a" }
> 0

That shouldn't be unexpected.  First, keep in mind that the characters
between the operator and the closing brace are, in effect, quoted, since
they are processed as a single unit (but that `quoted' is the wrong term
to use -- clear? ;-) ).

Now, consider what happens to a double quoted variable expansion when
it appears in the middle of a string: when expanded, if the expansion
is empty, it simply disappears.  For example, x"$a"y expands to `xy' when
x is unset or null.

When a variable expansion is wholly quoted, and the expansion is empty, the
result is a null argument.

So, the first example expands to "" (quoting is preserved).  The second
example expands to "  " (unquoted), which is removed by word splitting.

Chet

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




reply via email to

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