split svnversion output in bash
Question: I have this function, works fine, but I would like to rewrite it in bash. the
problem is, I have too little knowledge of what's available in bash.

    
    
    #!/usr/bin/python
    
    def parse_svnversion(value):
        """split the output of svnversion into its three components
    
        given a string that looks like the output of the command
        svnversion, returns the 3-tuple (low, high, flags)
    
        >>> parse_svnversion('1024')
        (1024, 1024, '')
        >>> parse_svnversion('1024:2000')
        (1024, 2000, '')
        >>> parse_svnversion('1024M')
        (1024, 1024, 'M')
        >>> parse_svnversion('1024:2000MP')
        (1024, 2000, 'MP')
        """
    
        values = filter(lambda x: x.isdigit() or x==':', value).split(':')
        return int(values[0]), int(values[-1]), filter(str.isalpha, value)
    
    if __name__ == '__main__':
        import doctest
        doctest.testmod()
    

what I would like is a similarly small bash function that I can invoke and
that will set something (three variables? an array?) that I can use. if it's
an array, I would really like it to be of fixed size (3).


Answer: This creates an array called "tuple" with three elements:

    
    
    [[ $(svnversion .) =~ ([0-9]+):*([0-9]*)([A-Z]*) ]]
    tuple[0]=${BASH_REMATCH[1]}
    tuple[1]=${BASH_REMATCH[2]:-${tuple[0]}}
    tuple[2]=${BASH_REMATCH[3]:-''}
    

Requires Bash 3.2 or greater. It may work in Bash >= 3 and < 3.2. Not portable
to the Bourne shell, although it can be adapted for the Korn shell or the Z
shell.

`ksh` uses the `.sh.match` array variable, for example: `${.sh.match[1]}`

`zsh` uses the `match` array variable, for example: `${match[1]}` or you can
do

    
    
    setopt bashrematch ksharrays
    

to have it work with the Bash version exactly as above.

The brace substitutions should be the same for all three.

