0

I'm trying to look for a file from a database. I'm getting the data from a php file just fine. It's just this one line I'm having issues with:

directory=`find ./ -type f -name "*$thismodelnormal*" -exec ls -la {} \;`

$thismodelnormal is just a string, but it's dynamic based on data from the database. Can anyone enlighten me on how to get this done? I've done a good bit of research already and couldn't find a solution.. surely somebody has done this before though.

5
  • Try putting an echo just before the find, to see the command you end up running. Does pasting it into your terminal (starting from PHP's working directory) give you what you expect? Commented Feb 23, 2013 at 6:29
  • Add set -x to the top of the script, to see the commands as they're executed. Commented Feb 23, 2013 at 6:33
  • @Barmar no way! That's awesome! Quick and easy fix. Adding as an Answer Commented Feb 23, 2013 at 6:42
  • It's not an answer, it's a way to debug your script and figure out what's wrong with it. Commented Feb 23, 2013 at 6:43
  • Well I added it anyway and elaborated to what the actual fix for that command is. Commented Feb 23, 2013 at 6:45

1 Answer 1

2

Adding set -x at the top of my script allowed me to view the command that are actually being run. In this case my command needed to be

directory=`find ./ -type f -name "*"$thismodelnormal"*" -exec ls -la {} \;`

NOTE the two sets of double quotes. One is for the find itself and the other extracts the variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.