如果我使用Linux Shell脚本在文本文件中搜索书籍名称,我想得到一个价格

时间:2019-04-03 17:19:59

标签: linux shell

我想仅通过使用书名从文本文件中获取价格。当我搜索书名时,应该从文本文件(book_name | author_name | price )中给我该书的价格。这样我就可以计算总价。

如果我按1,我的选项代码将带我进入Buy_book()功能:

while $1
do
    Options

    echo "Choose your option :"
    read input
    case $input in
        1) Add_book;;
        2) Search_data ;;
        3) Show_book;;
        4) Buy_book;;
        5) clear ;;
        6) break;;
        *) echo " !!! YOU ENTER WRONG INPUT !!!";;
    esac
done

我的Buy_book()函数:

Buy_book()
{
    while $1
    do 
        Show_year
        read Book_buy
        case $Book_buy in 
        1)
        2)
        3)
        4) clear;;
        5) break;;
        esac
    done
}

我的Add_book()函数:

Add_book()
{
    echo "------------------------Harinder book shop------------------------\n\n"
    Show_year #function show_year

    read input

    echo "Enter book name:"
    read Book_name
    echo "Enter author name: "
    read Author_name
    echo "Enter price:"
    read Book_price

    case $input in
         1) echo "\t$Book_name\t\t | \t$Author_name\t\t | \t$Book_price " >> ~/Desktop/Harinder/"B.A 1"/list1;;
         2) echo "\t$Book_name\t\t | \t$Author_name\t\t | \t$Book_price " >> ~/Desktop/Harinder/"B.A 2"/list2;;
         3) echo "\t$Book_name\t\t | \t$Author_name\t\t | \t$Book_price " >> ~/Desktop/Harinder/"B.A 3"/list3;;
         4) echo "!!!  You Enter wrong input  !!!";;
    esac
}

0 个答案:

没有答案