[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How test for directory with single quote (') in the name (with find)
From: |
Morgan Weetman |
Subject: |
Re: How test for directory with single quote (') in the name (with find)? |
Date: |
Wed, 4 Mar 2015 18:08:38 -0500 (EST) |
----- Original Message -----
> From: "Bernhard Voelker" <address@hidden>
> To: "Morgan Weetman" <address@hidden>, "Peng Yu" <address@hidden>
> Cc: address@hidden
> 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" .. :)