What you want is not easily possible because it is not possible to quote arbitrary strings from "outside" only (i.e. by enclosing in ""
or ''
). This could be done by quoting each character with \
but I don't see how that shall be done with simultaneously calling the shell.
This is possible:
echo "$DIR" | sed -e 's/./\\&/g' -e 's/^.*$/echo &/' | bash -s
But that cannot be put in an -exec
statement. And the echo
cannot be called from a shell because that shell would run into the quoting problem with the argument. You can make the find
output the shell input:
find ./\$my\'dir -type d -print0 | xargs -0 -n 1 ls
But: You could write the string to a file and have the shell read it from there:
find ./\$my\'dir -maxdepth 0 -type d -fprint tmpfile -exec bash -c 'cat tmpfile' \;
Sorry, no, not even that works: find
opens the file, does the -exec
action and afterwards writes to the file... So... this works but is kind of crazy, of course:
find ./\$my\'dir -maxdepth 0 -type d -fprint tmpfile -exec bash -c '(sleep 1; cat tmpfile)&' \;
sh -c
?-exec ls {}
should work.ls {} | grep
.find
and in order to examine a directory content you want to use-exec
,ls
andgrep
? That seems crazy to me.find
to find out all sub-directories that don't contain any pdf files. the command is:find . -type d ! -exec sh -c 'ls "{}" | grep -qi \.pdf' \; -print
. some directories make that failed, so the question came out, do you have any ideas to do that job?mv \$my\ \'dir/ 'my dir'
?