Re: eval and wildcard expansion problem

bung_ho_at_hotmail.com
Date: 06/23/05


Date: 23 Jun 2005 13:30:44 -0700

Chris F.A. Johnson wrote:
> On 2005-06-23, bung_ho@hotmail.com wrote:
> > ok, so in a (bash) script i'm trying to do the following:
> >
> > ---------
> > FINDLOGINLOGFILES="find $DIR/logs -name login*.log"
> >
> > # ... other stuff ...
> >
> > LOGINLOGINFILES=`$FINDLOGINLOGFILES`
> > ---------
> >
> > It's supposed to do what it looks like--I want to store the command
> > (with $DIR being substituted) in a variable, and then later execute
> > that command and store the results in another variable.
> >
> > This works for the most part until I encountered a situation when there
> > happened to be a file that satisfied the "login*.log" part in the PWD
> > when the script was run (not in $DIR). I thought that the double
> > quotes around the whole command should have protected the wildcard from
> > expansion by the shell, but it didn't, so when it came to executing the
> > command, it actually tried to do
> >
> > find mydir/logs -name login1.log login2.log
> >
> > which of course isn't what i want. i tried to protect it more by
> > changing the line to use single quotes around the login*.log, or to
> > backslash the *, but then the find command wouldn't actually find the
> > files in $DIR.
>
> When you do LOGINLOGINFILES=`$FINDLOGINLOGFILES`, there are no
> quotes.
>
> What you need is:
>
> FINDLOGINLOGFILES="find $DIR/logs -name 'login*.log'"
>
> --
> Chris F.A. Johnson <http://cfaj.freeshell.org>
> ==================================================================
> Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
> <http://www.torfree.net/~chris/books/cfaj/ssr.html>

Thanks for the reply. I did try that with the single quotes, also
tried escaping the *, but then when executed, the find command didn't
find the files in $DIR. I'm not really sure why, because when I try it
at the command line (i.e., with the single quotes), it does find them.
But in the script, it doesn't find them. Any idea what I might be
doing wrong?



Relevant Pages

  • Re: commands not waiting, /wait not helping
    ... > When executing an application that is a 32-bit GUI application, ... > the command prompt. ... > having a exe pathname with embedded spaces that needed to be in quotes. ... and wise needs to see switches before the scriptname. ...
    (microsoft.public.win32.programmer.tools)
  • Re: [SLE] bash Script Using Filenames with Embedded Spaces
    ... If it is a literal space for the ls command, ... wonder what effect the quotes will have placed in different places ... Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings College ...
    (SuSE)
  • Re: [SLE] bash Script Using Filenames with Embedded Spaces
    ... If it is a literal space for the ls command, ... wonder what effect the quotes will have placed in different places ... Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings College ...
    (SuSE)
  • Re: [SLE] bash Script Using Filenames with Embedded Spaces
    ... command, then it must be a literal space for any other command. ... Antonio Vivaldi-Gloria Dixit Dominus Magnificat Choir of Kings ... College Cambridge and the Academy of Ancient Music.m3u ... command is placed inside double quotes, I get the expected ls output: ...
    (SuSE)
  • Re: Bash commands: maybe they want to drive us crazy?
    ... Bill Unruh wrote: ... single quotes would cause the find command to expand the * ... Which means that a shell command and the shell itself are two very different ...
    (comp.os.linux.misc)