Yes, this is intentional.  By default, pathname expansion applies to all
arguments to simple commands.  You can do set -o noglob to turn off
pathname expansion.  You can do IFS='' to disable command splitting.

It can also be useful with typeset, for example
     typeset -a files=(*)


On Fri, Feb 20, 2015 at 9:13 AM, Clark Wang <[email protected]> wrote:

> On Thu, Feb 19, 2015 at 2:48 AM, Paulo César Pereira de Andrade <
> [email protected]> wrote:
>
>> Consider these sequences:
>>
>
> The results are all expected and the pathname expansion has nothing to do
> with typeset.
>
>>
>> $ touch stuff
>> $ typeset -A st*f
>>
>
> st*f would be expanded to stuff so this command is the same as typeset -A
> stuff.
>
>
>> $ typeset | grep st
>> associative array stuff
>>
>> $ set -o noglob
>> $ typeset -A st*f
>> ksh: typeset: st*f: invalid variable name
>>
>
> With -o noglob, st*f would not expand so this command is the same as
> typeset -A "st*f". And as the error message indicated it's not a valid var
> name.
>
>>
>> $ set -o glob
>> $ touch stuff[xyz]
>>
>
> This creates a file named "stuff[xyz]".
>
>
>> $ typeset -A st*f[xyz]
>> ksh: typeset: st*f[xyz]: invalid variable name
>>
>
> Since no files match the pattern, st*f[xyz] would "expand" to itself so
> this command is the same as typeset -A "st*f[xyz]" and again it's not a
> valid var name.
>
>
>> typeset -A st*f\[xyz\]
>>
>
> st*f\[xyz\] expands to the filename stuff[xyz] so this command is the same
> as typeset -A "stuff[xyz]" which declares stuff[xyz] as an associative
> array.
>
>
>> $ typeset -A stuff[x*z]
>>
>
> No files match stuff[x*z] so it expands to stuff[x*z] so this command is
> the same as typeset -A "stuff[x*z]" which declares stuff["x*z"] as an
> associative array.
>
>
>> $ typeset -A stuff[x?z]
>>
>
> Ditto.
>
>
>> $ typeset -A stuff\[x*z\]
>>
>
> The pattern expands to the filename "stuff[xyz]" so this command is the
> same as typeset -A "stuff[xyz]" which declares stuff[xyz] as an associative
> array.
>
>
>> $ typeset -p | grep stuff
>> typeset -A stuff=(['x*z']=() ['x?z']=() [xyz]=() )
>>
>
> So this result is as expected.
>
> -clark
>
>>
>> I believe this may not have been intended, as other ways
>> to create shell variables do not do path expansion.
>>
>> Thanks,
>> Paulo
>> _______________________________________________
>> ast-users mailing list
>> [email protected]
>> http://lists.research.att.com/mailman/listinfo/ast-users
>>
>
>
> _______________________________________________
> ast-users mailing list
> [email protected]
> http://lists.research.att.com/mailman/listinfo/ast-users
>
>
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to