2015-02-20 18:13 GMT-02:00 David Korn <dgk...@gmail.com>: > 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=(*)
Thanks. I believe this may be a bit confusing at first, because sometimes it will expand the variable name, and sometimes will error. The use of '*' and '?' are just to show the glob expansion, but use of '[' and ']' may be confusing. The original problem report I have is due to shell like this: ---8<--- $ cat test.sh #!/bin/ksh93 typeset -A stuff typeset -lui i=0 for (( i=0; i<100000; i++ )) do unset stuff[xyz] done ---8<--- and this: ---8<--- $ /usr/bin/strace -e trace=getdents ./test.ksh 2>&1 | /bin/grep -c getdents 200000 ---8<--- The way to fix this is to quote, as in unset 'stuff[xyz]', but this may look wrong for some people, so I did want to have some insight if it is expected or not. > On Fri, Feb 20, 2015 at 9:13 AM, Clark Wang <dearv...@gmail.com> wrote: >> >> On Thu, Feb 19, 2015 at 2:48 AM, Paulo César Pereira de Andrade >> <paulo.cesar.pereira.de.andr...@gmail.com> 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 ast-users@lists.research.att.com http://lists.research.att.com/mailman/listinfo/ast-users