- $?で判定のパターン
grep -e "hoge" hoge.txt
if [ $? -ne 0 ]; then
echo "error"
fi
- 条件文でコマンド実行のパターン
if ls hoge.txt ; then
echo "found"
else
echo "not found"
fi
grep -e "hoge" hoge.txt
if [ $? -ne 0 ]; then
echo "error"
fi
if ls hoge.txt ; then
echo "found"
else
echo "not found"
fi