cc:  [EMAIL PROTECTED]
Subject: Re: [ast-developers] Expanding empty arrays
--------

> I just stumbled across a discrepancy when quoting empty variables.
> 
>    set -- ""; print $#                                # prints 1
>    unset x; set -- "$x"; print $#             # prints 1
> 
> But:
> 
>    unset x; set -- "[EMAIL PROTECTED]"; print $#              # prints 0
>    typeset x; set -- "[EMAIL PROTECTED]"; print $#            # prints 0
> 
> I find this a little confusing. I always thought that any expression in 
> double quotes which evaluates to nothing counts as one word.
>
The behavior is correct.  The behavior of "$@" and "[EMAIL PROTECTED]"
expands to nothing if there are no arguments or array elements.

For "$@" this behavior is specified in POSIX and differs from the
Bourne shell.  It makes things like
        for i in "$@"
        do...
        done
behave as one would expect.

> Interestingly, bash exhibits a similar, though slightly more 
> inconsistent behavior:
> 
>     unset a; set -- "[EMAIL PROTECTED]"; echo $#              # prints 0
>     typeset a; set -- "[EMAIL PROTECTED]"; echo $#            # prints 1
> 
> I asked for that on the bash list and got an answer from Chet Ramey:
> 
> > ... Bash
> > has traditionally treated `typeset a' as equivalent to `typeset a=""'
> > instead of creating a `placeholder' variable that exists in a sort of
> > limbo.  That's different from things like `export a' or `readonly a',
> > and probably inconsistent enough to be worth changing for bash-4.0.
> 
> How is the situation in ksh? Is this behavior intended or will it also 
> change some day?
If no attribues are specified, then typeset creates an unset variable.
So this is a difference.
> 
> Regards,
> Bernd
> 
> -- 
> Bernd Eggink
> [EMAIL PROTECTED]
> http://sudrala.de
> _______________________________________________
> ast-developers mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-developers
> 

David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to