help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: small side issue with find


From: Alex fxmbsw7 Ratchev
Subject: Re: small side issue with find
Date: Thu, 4 Nov 2021 13:00:53 +0100

yeah i just reas carefully your reply
great fixed issue, thank you :) ketketgreygrey

On Thu, Nov 4, 2021, 12:59 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:

> ah i suppose the solution is to use -print .. ? thats all the difference i
> sqw on your working cmdline
>
> On Thu, Nov 4, 2021, 12:56 Greg Wooledge <greg@wooledge.org> wrote:
>
>> On Thu, Nov 04, 2021 at 12:35:05PM +0100, ikhxcsz7y xmbott wrote:
>> > i can at most show the script that i rewrote then with gawk grep -v
>> style
>>
>> Your attachment had type application/octet-stream which is really
>> inconvenient... oh well.
>>
>> Here are the relevant lines from your script:
>>
>> ex=( -name libTag -prune )
>> find=( find "${target[@]}" "${ex[@]}" -o -iname )
>> "${find[@]}" \*."$e"
>>
>> In other words, you are running a command of this form:
>>
>> find . -name libTag -prune -o -iname something
>>
>> Is that really so hard for you to just *say*?  Sheesh.
>>
>> Here's the result of your command:
>>
>> unicorn:~$ mkdir /tmp/x
>> unicorn:~$ cd /tmp/x
>> unicorn:/tmp/x$ mkdir good libTag
>> unicorn:/tmp/x$ touch good/file1 libTag/file2
>> unicorn:/tmp/x$ find . -name libTag -prune -o -iname 'file*'
>> ./libTag
>> ./good/file1
>>
>> Here's the result of the correct find command:
>>
>> unicorn:/tmp/x$ find . -name libTag -prune -o -iname 'file*' -print
>> ./good/file1
>>
>> Now, you may be asking: "Why do I need the -print on the end?  Isn't
>> that the default action?"
>>
>> It's difficult to find a nice, simple explanation for this.  Here's my
>> attempt to explain it, which may or may not be 100% accurate.
>>
>> If you omit the -print in this command, find assumes that you wanted
>> this:
>>
>> find . \( -name libTag -prune -o -iname 'file*' \) -print
>>
>> Here's what that does in my example setup:
>>
>> unicorn:/tmp/x$ find . \( -name libTag -prune -o -iname 'file*' \) -print
>> ./libTag
>> ./good/file1
>>
>> Looks exactly like what you didn't want, eh?
>>
>> Instead, you only wanted to -print the files that match the condition
>> on the right-hand-side of the -o.  Thus, you need to put the explicit
>> -print *there*.  Don't let find assume what you wanted.
>>
>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]