help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

surprising condition value in TRAP in 5.1


From: Robert E. Griffith
Subject: surprising condition value in TRAP in 5.1
Date: Wed, 3 Aug 2022 14:53:51 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

This DEBUG trap in a 5.0 Bash cmdline and again in a 5.1 Bash cmdline produces different results (line 3b is the difference)

   (1a) 5.0.17$ trap 'if ([[ "$BASH_COMMAND" =~ BOB  ]]); then echo "oh, no, not 
BOB"; fi; true' DEBUG
   (2a) 5.0.17$ echo hi
   (3a) hi
   (4a) 5.0.17$ echo BOB
   (5a) oh, no, not BOB
   (6a) BOB
   (7a) 5.0.17$


   (1b) 5.1.16$ trap 'if ([[ "$BASH_COMMAND" =~ BOB  ]]); then echo "oh, no, not 
BOB"; fi; true' DEBUG
   (2b) 5.1.16$ echo hi
   *(3b) oh, no, not BOB***(4b) hi
   (5b) 5.1.16$ echo BOB
   (6b) oh, no, not BOB
   (7b) BOB
   (8b) 5.1.16$

Under 5.1, only when the condition is inside the (), it returns true even though the [[]] cmd is false.

Is this known behavior?

The actual code that broke when I ran my scripts under 5.1 uses the ([[]]) so that it does not clobber the BASH_REMATCH of the actual cmd.

--BobG





reply via email to

[Prev in Thread] Current Thread [Next in Thread]