4 ms·
Uh... You can escape these sequences. But the escape character isn't the backslash for obvious reasons (it's the path separator). It's the backtick. > ni '
by justeleblanc 3y ago
Uh... You can escape these sequences. But the escape character isn't the backslash for obvious reasons (it's the path separator). It's the backtick.
> ni '[abc]'
Directory: C:\Users\<user>
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 21/04/2023 12:23 0 [abc]
> gi '[abc]'
# no output - would have matched files named a, b, or c
> gi '`[abc`]'
Directory: C:\Users\<user>
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 21/04/2023 12:23 0 [abc]
> gi -LiteralPath '[abc]'
Directory: C:\Users\<user>
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 21/04/2023 12:23 0 [abc]
> gi -lp '[abc]'
Directory: C:\Users\<user>
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 21/04/2023 12:23 0 [abc]
As far as I know that's been in powershell forever.
- 13of40 3y agoAh, OK. This works because you're using single quotes on your strings, meaning the escape sequence `[ is preserved until it reaches the globbing layer. This will not work, for example... gi "`[abc`]" ...because the `[ will be processed before the string gets sent to globbing, meaning the back tick will be removed. This would work with double quotes: gi "``[abc``]" ...because at the command line level this will evaluate to `[abc`] and the globbing will know that the square brackets are literal. So I will concede and downgrade my complaint from "impossible" to merely "overly complicated for the layman".
- justeleblanc 3y agoAnyone used to scripting languages knows there's a difference between single quotes and double quotes for escaping.
- LoganDark 3y ago> Anyone used to scripting languages knows there's a difference between single quotes and double quotes for escaping. Not necessarily. There are all sorts of scripting languages where single and double quotes are identical. It is, however, super common for there to be escaping differences in shell scripting languages.