Victor Lowther <[email protected]>:
> # Parsing the output of ls can lead to strange and subtle bugs.
> # Use globbing and parameter expansion instead, and go with the first
> # matching file.
>       local f
>       for f in "$r/$1" "$r/${1%%-*}-udev-%{1##*-}" "$r/"*"$1"; do
>               [[ -f $f ]] || continue
>               echo "$f"
>               return 0


Thank you for advice!  I've modified function to the following form:

# Final efect the same as previous, but in addition detects ambiguousness
# among multiple directories.  If it's not desired uncomment the line with
# "break" statement.
find_rule() {
    local rd f files=()

    [[ -f $1 ]] && { echo "$1"; return 0; }

    for rd in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
        for f in "$rd/$1" "$rd"/*-"$1"
        do
            [[ -f $f ]] || continue
            [[ ${f##*/} =~ [0-9][0-9]-.*\.rules ]] || continue
            files+=($f)
        done
        # (( ${#fil...@]} >= 1 )) && break
    done

    (( ${#fil...@]} < 1 )) && return 1
    (( ${#fil...@]} > 1 )) && {
        derror "Ambigous rules filename.  Matches: ${fil...@]}"
        return 1
    }

    echo "$files"
}


-- 
PGP key: 1024D/C284750D

Attachment: signature.asc
Description: PGP signature

Reply via email to