Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Crash with =~ in script, but not interactively



On 04/01/2008, Peter Stephenson <pws@xxxxxxx> wrote:
> On Fri, 4 Jan 2008 10:27:40 +0100
> "Mikael Magnusson" <mikachu@xxxxxxxxx> wrote:
> > I was going to make a wrapper script that replaces the :43: in gcc
> > warnings with +43 so i can open in vim easierly, but ran into some
> > problems.
> >
> > #!/bin/zsh
> > #this makes zsh segfault
> > if [[ $#@ = 1 ]]; then
> >       if [[ $1 =~ /?[^/]+:[0-9]+:$ ]]; then
> >               echo hello
> >       fi
> > fi
> >
> > If i save that in a file and run 'zsh file' it crashes, but if i run
> > 'source file' in an open shell it works as expected.
>
> Thanks, the problem was fairly obvious (luckily, since debugging the
> wordcode is another thing that's a nightmare).

Yep that worked. Does the =~ operator support backreferences? I didn't
find anything searching through the manual for the word. This is what
I ended up with instead which works too:

#!/bin/zsh
setopt extendedglob
if [[ $# = 1 ]]; then
	if [[ $1 = *[^/]##:(#b)([0-9]##)(#B): ]]; then
		2=+${1[$mbegin[1],$mend[1]]}
		1=${1[1,$mbegin[1]-2]}
	fi
fi
if [[ -z $DISPLAY ]] ; then vim $@; else; gvim $@; fi

in case anyone ever wanted something like that.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author