You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In Linux, Find Command Fails Even With Quoted and Escaped Asterisk #4680
PS> touch ab.txt 'a b.txt'# Question mark character works
PS> find -name 'a?.txt'
ab.txt
PS> find -name 'a??.txt'
a b.txt
# Asterisk appears to be being expanded into file names
PS> find -name 'a*b.txt'/usr/bin/find: paths must precede expression: ab.txt
Usage: /usr/bin/find [-H] [-L] [-P] [-Olevel] [-Dhelp|tree|search|stat|rates|opt|exec|time] [path...] [expression]
# Escaping asterisk doesn't work
PS> find -name 'a`*b.txt'# No output, which indicates the parameters were accepted, but the search produced no results.
According to that issue, the asterisk can be escaped using the backquote character, which appears to work for that case:
PS> echo '11:1'| grep '.`*:.'11:1
However, in the examples that were listed for this issue, using the backquote produced no results, but the command should have displayed the two newly created files.
PS> touch ab.txt 'a b.txt'
PS> find -name 'a`*b.txt'# No output, but should output the file names:# ./ab.txt# ./a b.txt
I'll try this example in the next beta and close this issue if the problem is solved.
EDIT: I've changed the name of this isssue to highlight the problem involving the quoted and escaped asterisk. If there's a better name, please let me know, or you can update the title if you'd like.
changed the title [-]Quoted Asterisk Causes Find Command to Fail in Linux[/-][+]In Linux, Find Command Fails Even With Quoted and Escaped Asterisk[/+]on Aug 27, 2017
'...' in PS encloses literals, and the newly introduced native globbing feature should treat them as such too. Not doing so is a bug.
(As is the interpretation of globbing patterns inside double-quoted PS strings).
In short: Using ` inside '...' before wildcard metacharacters is not a general workaround, nor should it be.
Adding a ` (backtick) before * disrupts the newly introduced PS-side globbing, but the ` character is passed through to the target utility, which is undesired.
(In PS, backticks only function as escape characters in unquoted or double-quoted strings.)
PS> printf '%s\n''`*'`*# ` was retained
It explains why your find -name 'a`*b.txt' workaround attempt didn't work.
The ` is also passed through in your grep example - it just happens to work even with the ` present, but that is unrelated to the issue at hand; you get the same behavior in bash:
# PS
PS> echo 'a'| grep '.`*'
a
# Bash
$ echo 'a'| grep '.`*'# !! effectively treated as '.*'
a
For reasons I don't understand, placing a ` before regex duplication symbols * and ? causes the ` to be ignored.
Activity
mklement0 commentedon Aug 27, 2017
Yes, globbing currently mistakenly also kicks in when the pattern is quoted.
A simpler example:
This was previously reported in #3931, and a fix is pending: #4489
[-]Quoted Asterisk Causes Find Command to Fail in Bash[/-][+]Quoted Asterisk Causes Find Command to Fail in Linux[/+]bigboy-pdb-spam commentedon Aug 27, 2017
According to that issue, the asterisk can be escaped using the backquote character, which appears to work for that case:
However, in the examples that were listed for this issue, using the backquote produced no results, but the command should have displayed the two newly created files.
I'll try this example in the next beta and close this issue if the problem is solved.
EDIT: I've changed the name of this isssue to highlight the problem involving the quoted and escaped asterisk. If there's a better name, please let me know, or you can update the title if you'd like.
[-]Quoted Asterisk Causes Find Command to Fail in Linux[/-][+]In Linux, Find Command Fails Even With Quoted and Escaped Asterisk[/+]mklement0 commentedon Aug 27, 2017
'...'in PS encloses literals, and the newly introduced native globbing feature should treat them as such too. Not doing so is a bug.(As is the interpretation of globbing patterns inside double-quoted PS strings).
In short: Using
`inside'...'before wildcard metacharacters is not a general workaround, nor should it be.Adding a
`(backtick) before*disrupts the newly introduced PS-side globbing, but the`character is passed through to the target utility, which is undesired.(In PS, backticks only function as escape characters in unquoted or double-quoted strings.)
It explains why your
find -name 'a`*b.txt'workaround attempt didn't work.The
`is also passed through in yourgrepexample - it just happens to work even with the`present, but that is unrelated to the issue at hand; you get the same behavior inbash:For reasons I don't understand, placing a
`before regex duplication symbols*and?causes the`to be ignored.