[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: If the expression contains *any action* anywhere (excluding -prune),
From: |
Peggy Russell |
Subject: |
Re: If the expression contains *any action* anywhere (excluding -prune), the user must provide all actions. |
Date: |
Tue, 5 Apr 2011 04:47:02 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Got it.
> It's true. The -exec and -delete predicates also (from memory, I'm
> not looking at the code right now) turn off the default of performing
> -print when the entire expression is true. If the documentation
> doesn't make this clear, could you raise a bug report on the website
> explaining where it would need to change?
When I did my first test with `-delete` the first thing I thought, whoa, how do
you log it. It's totally quiet. So is `rm`, but there is a `-v, --verbose`
option. It must have been mistakenly burned into my brain: "test [action]
[operator] repeat". But, you can actually have "action action...", to do
something like:
find . -iname "abc1.txt" -delete -printf "Deleting: %p\n"
^ ^
> > #3 "If the expression contains no actions other than `-prune', `-print' is
> > performed on all files for which the entire expression is true".
>
> I think this needs rephrasing, would you include it in your bug report please?
The bottom line seemed to be, I wasn't sure when an implicit `print` was going
to occur. Ah! Now I get it. If the expression contains *any action* anywhere,
the user must provide all actions. The exception to that rule is `-prune`. It is
the absent of any action that creates:
`\( entire expression \) -a -print`
So my examples:
# 1 - No: `-print`. Yes: `-prune`. No other action.
find . -path "foo" -prune -o -name "abc1.txt"
^
# Which is like:
find . \( -path "./foo" -prune -o -name "abc1.txt" \) -a -print
^ ^ ^ ^^^^
# Result:
./foo
./abc1.txt
# 2 - Yes: `-print`. Yes: `-prune`. (Watch for operator precedence)
find . -path "./foo" -prune -o -name "abc1.txt" -a -print
^ ^^^^
# which is like :
#
find . -path "./foo" -prune -o \( -name "abc1.txt" -a -print \)
^ ^ ^^^^ ^
# Result:
./abc1.txt
# 3 - No: `-print`. No: `-prune`. Yes: `-exec`.
find . -path "./foo" -exec echo "hi" \; -o -name "abc1.txt"
^
# Result:
hi
# Must add `-print` to #3 because a previous action was provided.
find . \( -path "./foo" -exec echo "hi" \; -o -name "abc1.txt" \) -a -print
^ ^ ^^^^
# OR
find . -path "./foo" -exec echo "hi" \; -print -o -name "abc1.txt" -print
^ ^
# Result:
hi
./foo
./foo/abc1.txt
./abc1.txt
> > For some reason, I assumed there was an implied `-print` in the command
> > below for the entire compound expression.
> >
> > find . -name "foo" -exec echo -n "hi:" \; -o -name "abc1.txt"
>
> Of course here there is an expression with a side effect, so there is
> no default -print.
I should have done this then:
find . \( -name "foo" -exec echo -n "hi:" \; -o -name "abc1.txt" \) -a -print
# OR
find . -name "foo" -exec echo -n "hi:" \; -print -o -name "abc1.txt" -print
^ ^
Question: What do you mean by "side effect"?
> > #4 The `-exec` above has an exit status success or true. Replace `-exec`
> > with `-true`. Shouldn't the output be the same as #3?
>
> No, because -true has no side effect.
>
> > find . -name "foo" -true -o -name "abc1.txt"
> > ./foo
> > ./foo/abc1.txt
> > ./abc1.txt
I equated `-true` to `-exec`, and I see my error. `-true` is a test while
`-exec`is an action.
I definitely have a better understanding of expression building in `find`.
Thank you.
Peggy Russell