bahsscriptが自宅のファイルで文字列を見つけたときにアクションを実行しようとしていますが、どういうわけか機能せず、理由がわかりません.. grepが0を返さないという印象があります(文字列は実際にはファイルに存在します)。
#!/bin/bash
find /home/ -type f | xargs grep -q 'stringtofind'
if [ $? == 0 ] #if the result is not equal to zero
then
echo "Action"
else
echo "Pas d'action"
exit 1
fi
exit 0
次のことをしているときに、シェルは 0 ではなく 123 を返します。
find /home/anselmewebsite/ -type f | xargs grep -q 'stringtofind' ; echo $?
shell returns : 123
ハイライトをお寄せいただきありがとうございます。