Jennifer Pioch wrote: > I know you can use globs in shell scripts, but how do I control when > the globbing is done? > > For instance > > pjfer at fragr:~:$ ls foo* > foo1 foo2 foo3 > pjfer at fragr:~:$ a=foo* > pjfer at fragr:~:$ echo $a > foo1 foo2 foo3 > pjfer at fragr:~:$ echo "$a" > foo* > > How do I get variable a to contain the expanded list of files, rather > than the glob itself?
Hi Jenny, this should do what you want: $ b=$(print $a) $ echo "$b" foo1 foo2 foo3 $ > One workaround I've found is to use ls to do it, but this seems very ugly > a=`ls foo*` Indeed, but fortunately 'ls' is not needed. We can stay within the shell using 'print' in a command substitution. And I'd recommend $( ... ) instead of the backquotes. > Presumably I could use a subshell to expand the variable, but I can't > get the syntax right. Command substitution used to be run in a subshell, but does not necessarily need to do so in ksh93 without external commands or pipelines. Cheers, Henk
