ES - Distinguish options from query text

Have a suggestion for "Everything"? Please post it here.
Post Reply
FstTesla
Posts: 2
Joined: Mon Mar 22, 2021 8:15 am

ES - Distinguish options from query text

Post by FstTesla »

When calling ES.exe, it is not possible (as far as I tried) to distinguish between options and the actual text of the query.

For example, if my query text contains the token -r (because I want to look for a filename containing the characters dash and R), this would be interpreted as the regular expression option flag instead of literal text.

Maybe it would be enough adding the typical -- (double dash) in order to signal the end of the options, so that everything after that is interpreted as literal query text by ES, of course letting alone any escape mechanisms needed by the shell (cmd, powershell, etc) itself.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: ES - Distinguish options from query text

Post by NotNull »

You could enclose your search in double quotes.
For example, to show the first 5 file-/foldernames with -r in their name:

Code: Select all

es.exe -n 5   "-r"
(extra spaces for clarity)
FstTesla
Posts: 2
Joined: Mon Mar 22, 2021 8:15 am

Re: ES - Distinguish options from query text

Post by FstTesla »

Thank you for your answer!

Your suggestion works fine when the shell is cmd.
Anyway, in order to obtain the same result in PowerShell, one has to write

Code: Select all

es.exe -n 5 '"-r"'   # or
es.exe -n 5 "`"-r`""
Of course who uses PowerShell should be aware of its parsing rules, but I think that relying on quotes in order to disambiguate options from query text is error-prone and there should be a more robust way to do that, such as an end-of-options signal like the widespread double dash.

Keep in mind that if someone experiments with the query in the UI and then tries to replicate it on the command line (e.g. for a script), forgetting quotes is very likely to happen, potentially leading to a different resultset; also IMO the solution you suggested is not so straightforward.

Es.exe is a command line tool, therefore targeted mainly to "technical" users, and nowadays people who write shell scripts prefer languages more powerful than cmd, such as PowerShell or any of the bash-like shells available through the WSL. Since many of these languages have rules that involve "complex" parsing and escaping of quotes, I think that this could be another reason for introducing an easier way to prevent ambiguous tokens to be interpreted as options.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: ES - Distinguish options from query text

Post by NotNull »

You should *always* be aware of quoting- and escaping issues, regardless what command processor/shell you are using.
A tool like ES.exe can only help so much with that.

For example, in PowerShell you need to be extremely cautious with [ , ] and ` characters in filenames or text. $ sometimes too.
In CMD that list is much longer and includes % , &, ^.
Post Reply