Menu

#71 pattern matching mismatch (bash 5.1)

v1.0_(example)
closed-fixed
nobody
None
5
2021-07-17
2021-07-12
No

pattern matching mismatch (bash 5.1) in $bashdb_location/lib/fns.sh
bashdb_location=/usr/share/bashdb

$ ./fns.sh

+ typeset -a _Dbg_eval_re
+ _Dbg_eval_re=('^[ \t]*(if|elif)[ \t]+([^;]*)((;[ \t]*then?)?|$)' 
                                                  '^[ \t]*return[ \t]+(.*)$' 
                                                  '^[ \t]*while[ \t]+([^;]*)((;[ \t]*do?)?|$)' 
                                                  '^[ \t]*[A-Za-z_][A-Za-z_0-9_]*[+-]?=(.*$)' 
                                                  "^[ \t]*[A-Za-z_][A-Za-z_0-9_]*\[[0-9]+\][+-]?=(.*\$)")
+ _Dbg_eval_extract_condition 'if test -z  ; then'
+ set -x
+ orig='if test -z  ; then'
+ [[ if test -z  ; then =~ ^[ \t]*(if|elif)[ \t]+([^;]*)((;[ \t]*then?)?|$) ]]
+ extracted='est -z  '

should be : extracted='test -z "$a"'

Discussion

  • Roland Christmann

    This patch should be applied to solve the bug :

    --- a/fns.sh
    +++ b/fns.sh
    @@ -58,11 +58,11 @@
     # gives syntax errors when this is put in place.
     typeset -a _Dbg_eval_re;
     _Dbg_eval_re=(
    
    -    '^[ \t]*(if|elif)[ \t]+([^;]*)((;[ \t]*then?)?|$)'
    -    '^[ \t]*return[ \t]+(.*)$'
    -    '^[ \t]*while[ \t]+([^;]*)((;[ \t]*do?)?|$)'
    -    '^[ \t]*[A-Za-z_][A-Za-z_0-9_]*[+-]?=(.*$)'
    -    "^[ \t]*[A-Za-z_][A-Za-z_0-9_]*\[[0-9]+\][+-]?=(.*\$)"
    +    '^[[:blank:]]*(if|elif)[[:blank:]]+([^;]*)((;[[:blank:]]*then?)?|$)'
    +    '^[[:blank:]]*return[[:blank:]]+(.*)$'
    +    '^[[:blank:]]*while[[:blank:]]+([^;]*)((;[[:blank:]]*do?)?|$)'
    +    '^[[:blank:]]*[A-Za-z_][A-Za-z_0-9_]*[+-]?=(.*$)'
    +    "^[[:blank:]]*[A-Za-z_][A-Za-z_0-9_]*\[[0-9]+\][+-]?=(.*\$)"
     )
    
     # Removes "[el]if" .. "; then" or "while" .. "; do" or "return .."
    
     

    Last edit: Roland Christmann 2021-07-12
  • Roland Christmann

    test case :
    $ cat -n mon_test.sh

    1 #!/bin/bash
    2 unset a
    3 if test -z "$a" ; then
    4 echo -e "a is not set ---> RC=\c" ; echo $?
    5 else
    6 echo -e "a has been set to $a" ; echo $?
    7 fi
    8 let a=666
    9 if test -z "$a" ; then
    10 echo -e "a is not set ---> RC=\c" ; echo $?
    11 else
    12 echo -e "a has been set to $a ---> RC=\c" ; echo $?
    13 fi
    14 if grep -qF "bummer" <<< 'a' ; then
    15 echo -e "nop ---> \c" ; echo $?
    16 elif [ 'a' != 'b' ] ; then
    17 echo -e "a is not equal to b ---> RC=\c" ; echo $?
    18 fi

    ./mon_test.sh output :
    a is not set ---> RC=0
    a has been set to 666 ---> RC=0
    a is not equal to b ---> RC=0


    /data # bashdb -- mon_test.sh
    bash debugger, bashdb, release 5.1-1.1.2

    Copyright 2002-2004, 2006-2012, 2014, 2016-2019 Rocky Bernstein
    This is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.

    (/data/mon_test.sh:2):
    2: unset a
    bashdb<0> b 3
    Breakpoint 1 set in file /data/mon_test.sh, line 3.
    bashdb<1> cont
    Breakpoint 1 hit (1 times).
    (/data/mon_test.sh:3):
    3: if test -z "$a" ; then
    bashdb<2> ev?
    eval: test -z "$a"
    $? is 0
    bashdb<3> b 9
    Breakpoint 2 set in file /data/mon_test.sh, line 9.
    bashdb<4> cont
    a is not set ---> RC=0
    Breakpoint 2 hit (1 times).
    (/data/mon_test.sh:9):
    9: if test -z "$a" ; then
    bashdb<5> ev?
    eval: test -z "$a"
    $? is 1
    bashdb<6> b 14
    Breakpoint 3 set in file /data/mon_test.sh, line 14.
    bashdb<7> cont
    a has been set to 666 ---> RC=0
    Breakpoint 3 hit (1 times).
    (/data/mon_test.sh:14):
    14: if grep -qF "bummer" <<< 'a' ; then
    bashdb<8> ev?
    eval: grep -qF "bummer" <<< 'a'
    $? is 1
    bashdb<9> b 16
    Breakpoint 4 set in file /data/mon_test.sh, line 16.
    bashdb<10> cont
    Breakpoint 4 hit (1 times).
    (/data/mon_test.sh:16):
    16: elif [ 'a' != 'b' ] ; then
    bashdb<11> ev?
    eval: [ 'a' != 'b' ]
    $? is 0
    bashdb<12> ev [ ! "${DO_NOT_TRACK:-0}" -eq 0 ]
    $? is 1
    bashdb<13> ev [ ! "${DO_NOT_TRACK:-0}" -eq 0 ]; echo $?
    1
    $? is 0
    bashdb<14>

     

    Last edit: Roland Christmann 2021-07-12
  • Roland Christmann

    Yes it is, I have just moved it from "ticket" to "bug".
    Thank you Rocky.

     
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-12
    • status: open --> closed-fixed
     
  • Roland Christmann

    Hello Rocky,

    Could you also fix it for zshdb ?

    Thanks.

     
  • Rocky Bernstein

    Rocky Bernstein - 2021-07-17

    While zshdb is related, it is a separate project. maintained on github. Please open a "pull request" or PR on github - thanks.

     

Log in to post a comment.