Habe exit-code 123 in der find + xargs grep

Hier ist mein Skript

eval "find \\( -type f -a \\( -name '*.h' \\) \\) -print0" | xargs -0 -n100 grep  -f <(echo "stdio")
echo $?

Nichts gefunden wird und der exit-code ist 123.

Wenn ich es ein wenig modifizieren und wie folgt

echo "stdio" >.P
eval "find \\( -type f -a \\( -name '*.h' \\) \\) -print0" | xargs -0 -n100 grep <.P
echo $?

Etwas gefunden, aber der exit-code ist noch 123.

Also, was ist falsch?

======================================================================

Eigentlich möchte ich nur schreiben, ein kleines script zu machen find+xargs+grep einfacher. Zum Beispiel,
xgrep -e MOTIV1 -e MOTIV2 ... *.c *.h
ausführen
find-name *.c -o -name *.h|xargs grep -f <(echo "$PATTEN1
$PATTERN2")

Verwenden Sie die option-f anstelle von-e ist um die Unannehmlichkeiten zu vermeiden, in die Flucht Einzel-oder Doppel-quations innerhalb der patterns.

#!/bin/bash
#set -e -o pipefail

eval ARGV=($(getopt -l '' -o 'e:li' -- "$@")) || exit 1
for((i=0;i<${#ARGV[@]};i++)) {
    o="${ARGV[$i]}"
    case $o in
    -e)
        i=$((i+1));
        a="${ARGV[$i]}"
        if [ -n "$grep_patterns" ]; then
            grep_patterns="$grep_patterns"$'\n'
        fi
        grep_patterns="$grep_patterns$a"
        ;;
    -i)
        grep_options="$grep_options -i"
        ;;
    -l)
        grep_options="$grep_options -l"
        ;;
    --)
        i=$((i+1));
        break;;
    esac
}

for((;i<${#ARGV[@]};i++)) {
    if [ -n "$find_options" ]; then
        find_options="$find_options -o "
    fi
    find_options="${find_options}-name '${ARGV[$i]}'"
}

cmd="find \\( -type f -a \\( $find_options \\) \\) -print0"
eval "$cmd" | xargs -0 grep $grep_options -f <(echo "$grep_patterns")
Warum sind Sie mit eval hier?

InformationsquelleAutor Pan Ruochen | 2014-10-24

Schreibe einen Kommentar