Ich bin mir nicht sicher, wie man eine if
mit mehreren Tests in der Shell zu tun. Ich habe Probleme mit diesem Skript zu schreiben:Mit if elif in Shell-Skripten
echo "You have provided the following arguments $arg1 $arg2 $arg3"
if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ]
then
echo "Two of the provided args are equal."
exit 3
elif [ $arg1 = $arg2 && $arg1 = $arg3 ]
then
echo "All of the specified args are equal"
exit 0
else
echo "All of the specified args are different"
exit 4
fi
Das Problem ist, ich bekomme diese Fehlermeldung jedes Mal:
./compare.sh: [: fehlt `]‘ Befehl nicht
gefunden
Nicht wenige Kommentatoren haben vorgeschlagen, dass Sie [[anstatt [aber das macht Ihr Skript bash-spezifisch. Sie werden weniger Wartungs- und Portabilitätsprobleme haben, wenn Sie sich an die einfache alte Bourne Shell (sh) -Syntax halten können. –