Bug 33820
| Summary: | [ and [[ behave differently with -eq | ||
|---|---|---|---|
| Product: | Sisyphus | Reporter: | Ivan Zakharyaschev <imz> |
| Component: | bash | Assignee: | Gleb F-Malinovskiy <glebfm> |
| Status: | CLOSED NOTABUG | QA Contact: | qa-sisyphus |
| Severity: | minor | ||
| Priority: | P3 | CC: | glebfm, ldv, placeholder |
| Version: | unstable | ||
| Hardware: | all | ||
| OS: | Linux | ||
Проверка актуальности. Различие задокументировано и воспроизводится в bash5 5.2.37 (контейнер Sisyphus): [ "a" -eq "b" ] → bash: [: a: integer expression expected, rc=2 [[ "a" -eq "b" ]] → истина Внутри [[ ]] операнды -eq вычисляются как арифметическое выражение, где неопределённое имя даёт 0, поэтому 0 -eq 0 истинно; test/[ требует целых чисел. Это поведение самого bash (см. bash(1), «Conditional Constructs»), не особенность сборки. Закрываю как NOTABUG. |

Description
Ivan Zakharyaschev 2017-08-28 18:25:16 MSK[ and [[ behave differently with -eq , although the info page give no hints about this: 6.4 Bash Conditional Expressions ================================ Conditional expressions are used by the '[[' compound command and the 'test' and '[' builtin commands. ... 'ARG1 OP ARG2' 'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'. These arithmetic binary operators return true if ARG1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to ARG2, respectively. ARG1 and ARG2 may be positive or negative integers. Examples of the difference: [imz@ovicaa ~]$ [ a -eq b ] && echo yes bash: [: a: integer expression expected [imz@ovicaa ~]$ [[ a -eq b ]] && echo yes yes [imz@ovicaa ~]$ rpm -q bash bash-3.2.57-alt1 -bash-4.3# [ a -eq b ] && echo yes -bash: [: a: integer expression expected -bash-4.3# [[ a -eq b ]] && echo yes yes -bash-4.3# rpm -q bash bash-4.3.42-alt2.x86_64