![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find command from a shell script | kodermanna | UNIX for Advanced & Expert Users | 6 | 01-28-2008 02:37 AM |
| Problem with find command when used with mtime | arunkumar_mca | UNIX for Dummies Questions & Answers | 4 | 01-07-2008 08:37 PM |
| Problem with find command in C-shell | dhanamurthy | UNIX for Advanced & Expert Users | 3 | 11-30-2006 01:16 AM |
| urgent: problem with find command | Terrible | UNIX for Advanced & Expert Users | 10 | 06-07-2006 11:11 PM |
| Problem with find command | nattynatty | Shell Programming and Scripting | 7 | 05-15-2002 09:16 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
find command from shell scipt (ksh) problem
Hi experts,
I have a simple shell script as follows. #!/bin/ksh FIND_STRING="\( -name 'testfile*.Z' -o -name 'DUMMY_*' \) " find /tmp -type f $FIND_STRING -print When I run this with ksh -x testscript, I get the following output. + FIND_STRING=\( -name 'testfile*.Z' -o -name 'DUMMY_*' \) + find /tmp -type f \( -name 'testfile*.Z' -o -name 'DUMMY_*' \) -print find: 0652-009 There is a missing conjunction If I cut and paste the second line of the output into the dollar prompt, it works fine. Donot know what is happening . I had posted a similar error few weeks before, but now I could pinpoint to a 2 liner. Thanks in advance for your help. |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
|
|
|||
|
Well, "$FIND_STRING" is being evaluated in that the variable name is being replaced with the variable contents. However, the contents themselves are not being evaluated...that would be double-evaluation, a 15-yard penalty.
You could either use the command 'eval' in front of the 'find' command, or just remove the backslashes when you set the string. |
|
|||
|
Here is the ouput when you do set -x on the script
Code:
+ FIND_STRING=$'\\( -name \'testfile*.Z\' -o -name \'DUMMY_*\' \\)'
+ echo '\(' -name $'\'testfile*.Z\'' -o -name $'\'DUMMY_*\'' '\)'
\( -name 'testfile*.Z' -o -name 'DUMMY_*' \)
+ find /tmp -type f '\(' -name $'\'testfile*.Z\'' -o -name $'\'DUMMY_*\'' '\)' -print
find: \(: unknown option
Code:
eval find /tmp -type f $FIND_STRING -print |
|
|||
|
Thank you very much
Thanks a lot for your explanation and the eval works fine. I had not used eval before and didn't know it is so vital. I haven't fully digested the solution but will spend some time on it.
Thanks again for your kind help. |
|
|||
|
Basically eval causes a shell to parse a command line twice. The following simple example should help clarify things
Code:
name=PATH echo $name eval echo $name eval echo $$name eval echo \$$name |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|