find vs. $FIND, perhaps subshell problem

find vs. $FIND, perhaps subshell problem

Post by Buffy The Cache Cod » Sat, 09 Feb 2002 01:56:34



I have the following script:

#!/usr/bin/ksh
REGEXP=$1
FILE=$2
FIND_C="find . -follow -name '*.c' -exec egrep -i '$REGEXP' /dev/null {} \;"
#Works
find . -follow -name '*.c' -exec egrep -i "$REGEXP" /dev/null {} \; > $FILE
# Does not work
$FIND_C > $FILE
#Works
eval $FIND_C ">" $FILE

Okay, now if I take the file redirection out, the results above still hold:
find ...     #works -->regexp found
$FIND_C      #fails -->quietly works, but with no results
eval $FIND_C #works -->regexp found

Assuming that I'm not doing anything stupid 8)... why does the second
one fail?

I'm wondering if there is some subtle interaction going on between
subshells, or maybe in the second one, the shell doesn't interpret
$FIND_C twice like it would in eval?

that is in the eval line, the current shell interprets $FIND_C, then
eval interprets the interpretation in a subshell.  Is that right?

thanks again.

 
 
 

find vs. $FIND, perhaps subshell problem

Post by Dr. Yuan Li » Sat, 09 Feb 2002 03:30:34



Quote:

> I have the following script:

> #!/usr/bin/ksh
> REGEXP=$1
> FILE=$2
> FIND_C="find . -follow -name '*.c' -exec egrep -i '$REGEXP' /dev/null {} \;"
> #Works
> find . -follow -name '*.c' -exec egrep -i "$REGEXP" /dev/null {} \; > $FILE
> # Does not work
> $FIND_C > $FILE
> #Works
> eval $FIND_C ">" $FILE

> Okay, now if I take the file redirection out, the results above still hold:
> find ...     #works -->regexp found
> $FIND_C      #fails -->quietly works, but with no results
> eval $FIND_C #works -->regexp found

> Assuming that I'm not doing anything stupid 8)... why does the second
> one fail?

Why you have single quote in 2 but double quote in 1?  eval "strips
away" that single quote in $FIND_C, so it works again.

- Show quoted text -

Quote:> I'm wondering if there is some subtle interaction going on between
> subshells, or maybe in the second one, the shell doesn't interpret
> $FIND_C twice like it would in eval?

> that is in the eval line, the current shell interprets $FIND_C, then
> eval interprets the interpretation in a subshell.  Is that right?

> thanks again.


 
 
 

1. Linux Find vs FreeBSD Find

Warning: possible newbie question!!

I run FreeBSD 3.2. I was helping a friend who is running Linux, and we had
to do a find. His find barely touched the hard drive, and came up with a
result almost immediately. The find on FBSD churns away, recursing each
directory, and takes quite a while on a large volume. I can only assume that
the Linux version of find is indexed in some way. Does FBSD have this
capability?

TIA

Bob/

2. Running a command if argument exist

3. Need to find vi command to remove ^H from command man find > find.txt

4. Switching Redhat window manager

5. find without the "find: cannot read dir /usr/lost+found: Permission denied"

6. Installing Linux Mandrake 7!

7. find, find, find

8. LILO Configuration problem 010101

9. Perhaps i found the solution

10. Lost Memory found, perhaps.

11. Linux 2.4.x Kernel Bug - Problem NOT found, but found workaround

12. `Nested (`Nested Subshells`) Subshells`

13. tcsh - to subshell or not to subshell