#!/bin/bash
library=mylibrary
tmp=mylibrary.tmp
function add_book {
echo Please enter the book title:
read title
existed=`awk -F '$1 == $title' $library | wc -l`
echo $existed
if (( $existed == 0 ))
then
echo Please enter the author:
read author
location=library
updated=$title,$author,$location,`date +%F`
echo $updated >> $library
echo $updated return successfully!
else
echo "Book Exist!"
fi
((我想要做的是比较标题,如果标题存在,那么回声“预定存在”
我想要将输入与文本文件进行比较))
这是一个示例文本文件:
Title,Author,Location,Date Added
jj,jj,library,2013-11-14
hjj,hj,library,2013-11-14
jhj,hjh,library,2013-11-14
答案 0 :(得分:0)
你的脚本有很多问题,但这似乎是一个阻碍问题:
existed=`awk -F '$1 == $title' $library | wc -l`
将其更改为:
existed=$(awk -v title="$title" -F '$1 == title{i++} End{print i}' "$library")
-v name="$value"
语法