Bourne Shell Script で学生データベースの構築に取り組んでいます。以前にファイルに入力されたデータ行を更新できるようにする必要がありますが、その方法がわかりません。これは私が試したことです:
echo "please enter the name: \c"
read updateInput
updateNumber=$(grep -cwi $updateInput database.txt)
if [ "$updateNumber" -gt "1" ]
then
echo "ambiguous input"
elif [ ! grep -iq "$updateInput" database.txt ]
then
echo "record not found"
else
lineNumber=$(grep -ni $updateInput database.txt)
grep -i $updateInput database.txt > tmp
read first last age course1 course2 < tmp
echo "record found, enter new value now:"
echo "name ($first $last): \c"
read first last
echo "age ($age): \c"
read age
echo "course-1 ($course1): \c"
read course1
while ! fgrep -iwq "$course1" $FILE
do
echo "course does not exist"
echo "course-1: \c"
read course1
done
echo "course-2 ($course2): \c"
read course2
while ! fgrep -iwq "$course2" $FILE
do
echo "course does not exist"
echo "course-2: \c"
read course2
done
fi
しかし、それは明らかにファイルをまったく更新していません。特定の行を取得してそのデータを変更する方法がわかりません。
また、私の elif ステートメントは機能しません。私はそれで何が間違っているのか疑問に思っていました.
みんな、ありがとう。私は Bourne Shell Script の初心者で、これを機能させるのにかなり苦労しました。