[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: |
Dale R. Worley |
Subject: |
Re: How test for directory with single quote (') in the name (with find)? |
Date: |
Thu, 05 Mar 2015 22:23:00 -0500 |
Peng Yu <address@hidden> writes:
> /tmp/tryfind$ find . -type f
> ./'/.export
> /tmp/tryfind$ find . -type d -exec sh -c "test -d '{}'/.export" ';' -print
> sh: -c: line 0: unexpected EOF while looking for matching `''
> sh: -c: line 1: syntax error: unexpected end of file
The problem is that you're constructing the string
test -d '/.export
and then handing it to sh to execute. But sh applies complex parsing
rules, and if there's a ' in the string, it is considered a quoting
character.
What you want to do is write
find . -type d -exec test -d {}/.export ';' -print
When find locates the ' directory, it assembles three strings that form
the command it is to execute:
test
-d
./'/.export
The nice thing is that find does not put those through sh, but rather
executes the exec() call itself, so when test runs it sees two
arguments: -d and ./'/.export. test then gives the answer you expect.
Dale