Menu

#62 hook.sh syntax error at line 285

v1.0_(example)
open
nobody
5
2019-10-07
2019-10-03
Wybo
No
# bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

# bashdb --version
bashdb, release 5.0-1.1.0

# cat bashdb-test
#!/bin/bash
line='= asd'
if [[ "$line" =~ ^=\ (.*) ]]; then 
   echo yes
else
   echo no
fi
echo bye

When I bashdb on this file and type next trhee times I get this error mesaage:

/usr/share/bashdb/lib/hook.sh: eval: line 285: conditional binary operator expected
/usr/share/bashdb/lib/hook.sh: eval: line 285: syntax error near `asd'
/usr/share/bashdb/lib/hook.sh: eval: line 285: `[[ = asd =~ ^=\ (.*) ]]'

although everything else runs as expected.

1 Attachments

Discussion

  • Rocky Bernstein

    Rocky Bernstein - 2019-10-03

    Commit #57b18c2 might fix things. Please double check though.

    This is about all the time in the near future I'll be able to spend on this. In case you want to improve or work up a regression test based on your test, here is what was going on.

    We need to save and BASH_REMATCH going into the debugger and restore it leaving so that if the debugged program uses that variable it has the value it set rather than something the debugger might have set.

     
  • Rocky Bernstein

    Rocky Bernstein - 2019-10-07

    On Mon, Oct 7, 2019 at 3:04 PM tien ho van hvtien.ch@gmail.com wrote:

    Hi Rocky,

    I just saw your patch this morning, applied it and tested again. It resolved my problems. I think your idea to put it to read only is great, really very good, because is more reliable and we don't need to executed this.
    Therefore I think we need also to delete the following line too, which I put actually in comment.

     _Dbg_hook_enter_debugger() {
         _Dbg_stop_reason="$1"
         [[ 'noprint' != $2 ]] && _Dbg_print_location_and_command
         _Dbg_process_commands
         _Dbg_set_to_return_from_debugger 1 # Persist the user-space value of BASH_REMATCH in user space 
         # eval $_Dbg_last_regmatch_command
          return $_Dbg_continue_rc
     } 
    

    I already tested it.

    I am not totally sure what you mean, but when eval $_Dbg_last_regmatch_command is commented out, then BASH_REMATCH might not be not set properly on debugger exit.

    As a result a program like this:

    regex='aa(b{2,3}[xyz])cc'
    for word in aab aabbxcc aabbcc; do
        if [[ $word =~ $regex ]]; then
            echo "$word matches"
            i=1
            n=${#BASH_REMATCH[*]}
            while [[ $i -lt $n ]]
            do
                echo "  capture[$i]: ${BASH_REMATCH[$i]}"
                let i++
            done
        else
            echo "$word does not match"
        fi
        shift
    done
    

    Will not work properly when it is stepped through.

    If I can help you, just let me know.

    What would be a big help would be to write a test case that incorporates both bash scripts that might fail: the one that you started with and the one I just gave.

    Thanks for all the help.

     

    Last edit: Rocky Bernstein 2019-10-07

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.