----- Original Message ----- > From: "Bernhard Voelker" <m...@bernhard-voelker.de> > To: "Morgan Weetman" <mweet...@redhat.com>, "Peng Yu" <pengyu...@gmail.com> > Cc: bug-findutils@gnu.org > Sent: Thursday, 5 March, 2015 9:39:52 AM > Subject: Re: How test for directory with single quote (') in the name (with > find)? > > On 03/04/2015 11:17 PM, Morgan Weetman wrote: > > The example below has assumed that you wanted to test that .export was a > > file: > > > > find . -type d -exec sh -c "test -f \"{}\"/.export" \; -print > > > > .. works for me on 4.5.11 > > Well, the problem is when now a directory has a double quote '"' in its name: > > $ mkdir 'hello"world' > $ touch 'hello"world/.export" > $ find . -type d -exec sh -c "test -f \"{}\"/.export" \; -print > sh: -c: line 0: unexpected EOF while looking for matching `"' > sh: -c: line 1: syntax error: unexpected end of file > > The best I could think of is to avoid the extra shell, and to directly > invoke /usr/bin/test instead: > > $ find . -type d -exec test -f '{}'/.export \; -print > > This will work for both, directory names with '"' and with '\'' in their > names. > > Have a nice day, > Berny > >
My first advice was going to be "don't have directory names with quotes in them" .. :)