diff --git a/tools/ds-identify b/tools/ds-identify index e5120ac4271b..b0f8670d1a48 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -777,21 +777,25 @@ check_config() { if [ "$1" = "$files" -a ! -f "$1" ]; then return 1 fi - local fname="" line="" ret="" found=0 found_fn="" - # shellcheck disable=2094 - for fname in "$@"; do - [ -f "$fname" ] || continue - while read line; do - line=${line%%#*} - case "$line" in - $key:\ *|"${key}":) - ret=${line#*:}; - ret=${ret# }; - found=$((found+1)) - found_fn="$fname";; - esac - done <"$fname" + local line="" ret="" found=0 found_fn="" oifs="$IFS" out="" + debug 1 "looking for '$key' in $# files: $*" + out=$(grep "$key\"\?:" "$@" 2>/dev/null) + IFS=${CR} + for line in $out; do + # drop '# comment' + line=${line%%#*} + # if more than one file was 'grep'ed, then grep will output filename: + # but if only one file, line will not be prefixed. + if [ $# -eq 1 ]; then + found_fn="$1" + else + found_fn="${line%%:*}" + line=${line#*:} + fi + ret=${line#*: }; + found=$((found+1)) done + IFS="$oifs" if [ $found -ne 0 ]; then _RET="$ret" _RET_fname="$found_fn"