0

There's a question How to find files that contain newline in filename?, where the accepted answer handles isolating files with newlines via ANSI-C quoting, and that works fine in ksh and bash, but how would I handle that in a POSIX shell ? Specifically, I'm using dash.

1 Answers1

1

After discussion in comments and looking at the related question referenced in mine, one way use newlines in -name is to use literal newline as in:

$ find -type f -name '*
> *'

Another is via command-substitution:

$ find -name "$(printf '*\n*' )"
./with?newline
$ ls
another execve with?newline

But beware that POSIX definition, command substitution is performed by shell with "...removing sequences of one or more characters at the end of the substitution". That is something like:

find -type f -name '*'"$(printf '\n')"'*'

fails and passes ** in argument list instead of *[newline]* as one would think.

The trailing newlines in command substitution can be handled in couple ways as shown at shell: keep trailing newlines ('\n') in command substitution.