bashの中で二重grep比較を使うにはどうすればよいですか?二重grep比較をbash内で使うにはどうすればいいですか?
は、私が実行するトリングだ:
if [grep -q $HOSTNAME /etc/hosts] && [grep -q $IP /etc/hosts]
then
echo $HOSTNAME and $IP is found into /etc/hosts, test passed OK.
else
# code if not found
echo The Hostname $HOSTNAME'/'IP $IP is not found in /etc/hosts, please append it manually.
exit 1;
fi
が、取得エラーメッセージ:*too many arguments*
が間違って何ですか?
if grep -q "foo" /etc/hosts && grep -q "bar" /etc/hosts; then
# Both foo and bar exist within /etc/hosts.
else
# Either foo or bar or both, doesn't exist in /etc/hosts.
fi
あなたのエラーの理由は、あなたが[
コマンドを使用することができないということです。
'test'コマンド(別名' [')はファイルをチェックし値を比較するためのものです。あなたの 'grep'から' [''] 'を削除してください。 – SLePort