Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:02:29+00:00 2026-05-29T23:02:29+00:00

The following command works as expected interactively, in a terminal. $ find . -name

  • 0

The following command works as expected interactively, in a terminal.

$ find . -name '*.foo' -o -name '*.bar'
./a.foo
./b.bar
$

However, if I do this, I get no results!

$ ftypes="-name '*.foo' -o -name '*.bar'"
$ echo $ftypes
-name '*.foo' -o -name '*.bar'
$ find . $ftypes
$

My understanding was/is that $ftypes would get expanded by bash before find got a chance to run. In which case, the ftypes approach should also have worked.

What is going on here?

Many thanks in advance.

PS: I have a need to dynamically build a list of file types (the ftypes variable above) to be given to find later in a script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:02:31+00:00Added an answer on May 29, 2026 at 11:02 pm

    Both answers so far have recommended using eval, but that has a well-deserved reputation for causing bugs. Here’s an example of the sort of bizarre behavior you can get with this:

    $ touch a.foo b.bar "'wibble.foo'"
    $ ftypes="-name '*.foo' -o -name '*.bar'"
    $ eval find . $ftypes
    ./b.bar
    

    Why didn’t it find the file ./a.foo? It’s because of exactly how that eval command got parsed. bash’s parsing goes something like this (with some irrelevant steps left out):

    1. bash looks for quotes first (none found — yet).
    2. bash substitutes variables (but doesn’t go back and look for quotes in the substituted values — this is what lead to the problem in the first place).
    3. bash does wildcard matching (in this case it looks for files matching '*.foo' and '*.bar' — note that it hasn’t parsed the quotes, so it just treats them as part of the filename to match — and finds 'wibble.foo' and substitutes it for '*.foo'). After this the command is roughly eval find . -name "'wibble.foo'" -o "'*.bar'". BTW, if it had found multiple matches things would’ve gotten even sillier by the end.
    4. bash sees that the command on the line is eval, and runs the whole parsing process over on the rest of the line.
    5. bash does quote matching again, this time finding two single-quoted strings (so it’ll skip most parsing on those parts of the command).
    6. bash looks for variables to substitute and wildcards to matching, etc, but there aren’t any in the unquoted sections of the command.
    7. Finally, bash runs find, passing it the arguments “.”, “-name”, “wibble.foo”, “-o”, “-name”, and “*.bar”.
    8. find finds one match for “*.bar”, but no match for “wibble.foo”. It never even knows you wanted it to look for “*.foo”.

    So what can you do about this? Well, in this particular case adding strategic double-quotes (eval "find . $ftypes") would prevent the spurious wildcard substitution, but in general it’s best to avoid eval entirely. When you need to build commands, an array is a much better way to go (see BashFAQ #050 for more discussion):

    $ ftypes=(-name '*.foo' -o -name '*.bar')
    $ find . "${ftypes[@]}"
    ./a.foo
    ./b.bar
    

    Note that you can also build the options bit by bit:

    $ ftypes=(-name '*.foo')
    $ ftypes+=(-o -name '*.bar')
    $ ftypes+=(-o -name '*.baz')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following command works as expected... tail /var/log/mysqld.log | grep `date '+%y%m%d' --date='1 day
When I use the following code in command prompt, it works fine. But when
When I try to run this page (video.php), I get the following error: Parse
When running a C# application under mono with the mono command, the following works:
The following Groovy commands illustrate my problem. First of all, this works ( as
The following command in a batch file does not work as expected/hoped: echo %~nxs1
I added following command to Sessions -> Startup program but it didn't work. I'm
Following command will let me know the names of databases. $ mysqlshow But how
The following command gives many manuals of Zsh man zsh<tab> alt text http://dl.getdropbox.com/u/175564/zsh.png I
I currently use the following command, but it's a little unwieldy to type. What's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.