[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: |
Bernhard Voelker |
Subject: |
Re: How test for directory with single quote (') in the name (with find)? |
Date: |
Wed, 04 Mar 2015 23:39:52 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
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