helpThe GNU Bourne-Again SHell - Support: sr #108110, [bug] righthand of = or == in [[...


sr #108110: [bug] righthand of = or == in [[ ]] seems to do quote removal on expanded variables

Submitted by:  Michal Soltys <msoltyspl>
Submitted on:  Fri 17 Aug 2012 11:40:52 PM UTC  
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: OpenOperating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


Fri 13 Nov 2015 02:35:45 PM UTC, comment #2:

Not a bug. When == or = is used with the [[ compound command, it performs pattern matching. There is no quote removal performed, so the backslash is preserved, but the backslash has special meaning to the pattern matcher. There is no difference between == and =, both perform pattern matching.

That's why you can quote the rhs to get string matching.

Chet Ramey <chet>
Project Administrator
Fri 24 Aug 2012 10:26:33 AM UTC, comment #1:

One correction: for == operator the behavior is fine (righthand is treated as a pattern and in such case backslash is removed), but for = it's still invalid.

Michal Soltys <msoltyspl>
Fri 17 Aug 2012 11:40:52 PM UTC, original submission:

Essentially, if someone does:

set -x
[[ $a = $a ]]

Then the result (as of 4.2.37) will be false (even though debug output shows expected evaluation). The only way to get true is to quote righthand $a (or both). If I'm not missing any subtlety - I think it's not how it should be - as it looks like quote removal is sneaking in at some point modifying effects of earlier expansions.

Michal Soltys <msoltyspl>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by chet (Posted a comment)
  • -unavailable- added by msoltyspl (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 13 Nov 2015 02:35:45 PM UTCchetStatusNone=>Invalid

    Back to the top

    Powered by Savane 3.1-cleanup