grep函數不能以正確的方式工作。如何在這種情況下使用grep?
這裏是我的代碼:
echo -n "Title: " # prompt user for title
read title # get input from keyboard
echo -n "Author: " # prompt user for author
read author # get input from keyboard
if grep -q -i -w $title BookDB.txt # check for title in BookDB.txt
then # if duplicate exist
clear # clear screen
echo "Error! Book already exists!" # prompt user about duplicated entry
echo " " # newline
continue # display main menu
else # if duplicate absent
echo -n "Price: " # prompt user for price
read price # get input from keyboard
echo -n "Qty Available: " # prompt user for qty available
read qtyAvail # get input from keyboard
echo -n "Qty Sold: " # prompt user for qty sold
read qtySold # get input from keyboard
如
的「指環王」是BookDB.txt
如果我想添加新書,將檢查它是否存在一個不是。
但是,如果我想添加「石頭之王」,它說已經存在。 請提供諮詢。
5行是我放棄bash和寫在一個適當的語言,如Python的點。 – Spacedman