idank / explainshell

match command-line arguments to their help text
GNU General Public License v3.0
13.29k stars 794 forks source link

POSIX test(1) integer and file operators not understood: -eq -ge -gt -le -lt -ne -ef -nt -ot #276

Open ulidtko opened 3 years ago

ulidtko commented 3 years ago

Hi!

Didn't find this reported. The issue title is pretty much a complete description. Example: https://explainshell.com/explain?cmd=test+7+-eq+5 — parses -eq as -e incorrectly.

POSIX manpage defines the operators in this way:

  -x pathname
   True if pathname resolves to an existing directory entry for a file for which permission to execute [...]
  -z string True if the length of string string is zero; otherwise, false.
  string   True if the string string is not the null string; otherwise, false.
  s1 = s2  True if the strings s1 and s2 are identical; otherwise, false.
  s1 != s2  True if the strings s1 and s2 are not identical; otherwise, false.
  n1 -eq n2 True if the integers n1 and n2 are algebraically equal; otherwise, false.
  n1 -ne n2 True if the integers n1 and n2 are not algebraically equal; otherwise, false.
  n1 -gt n2 True if the integer n1 is algebraically greater than the integer n2; otherwise, false.

Ubuntu's description is different:

  STRING1 = STRING2
         the strings are equal

  STRING1 != STRING2
         the strings are not equal

  INTEGER1 -eq INTEGER2
         INTEGER1 is equal to INTEGER2

  INTEGER1 -ge INTEGER2
         INTEGER1 is greater than or equal to INTEGER2

  INTEGER1 -gt INTEGER2
         INTEGER1 is greater than INTEGER2

I would try to fix this in a PR, given that'd be simple enough.

But not at all sure if retraining a classifier would be simple enough.

Did you @idank put in a way to "manually override" ML mistakes with hand-written code?.. That could be useful to cover quirky writing/formatting of any stubborn manpage. I imagine, a community effort to transcribe the most important commands (like test, read, the foundational stuff) accurately could greatly increase the appeal and impact of the project.

https://explainshell.com looks really cool, that's true, honestly well done. But I'm suggesting the above, simply due to having rediscovered the site, again, since years ago — and getting quickly disappointed with it, again. Doesn't matter how cool it looks if I can't use it to explain a complicated construction to someone (e.g. while test 7 -eq $(curl -s localhost:1234; echo $?); do sleep 0.1; done), because basic stuff like test operators is not accurate.