help-bash
[Top][All Lists]
Advanced

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

[Help-bash] ${#BASH_REMATCH[*]}


From: J. M.
Subject: [Help-bash] ${#BASH_REMATCH[*]}
Date: Wed, 8 Feb 2012 00:44:34 +0800

Dear list,

One example from:

http://www.linuxjournal.com/content/bash-regular-expressions

if [[ $# -lt 2 ]]; then
    echo "Usage: $0 PATTERN STRINGS..."
    exit 1
fi
regex=$1
shift
echo "regex: $regex"
echo

while [[ $1 ]]
do
    if [[ $1 =~ $regex ]]; then
        echo "$1 matches"
        i=1
        n=${#BASH_REMATCH[*]}  ##### dose someone know what's going on
with this part? I am totally confused.
        while [[ $i -lt $n ]]
        do
            echo "  capture[$i]: ${BASH_REMATCH[$i]}"
            let i++
        done
    else
        echo "$1 does not match"
    fi
    shift
done


M.



reply via email to

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