Bug 33820 - [ and [[ behave differently with -eq
Summary: [ and [[ behave differently with -eq
Status: NEW
Alias: None
Product: Sisyphus
Classification: Development
Component: bash (show other bugs)
Version: unstable
Hardware: all Linux
: P3 minor
Assignee: placeholder@altlinux.org
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-28 18:25 MSK by Ivan Zakharyaschev
Modified: 2017-08-28 18:25 MSK (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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