以下是图书管理系统的示例 shell 脚本:
#!/bin/bash
# 登录系统
if [ "$#" -eq 0 ]; then
echo "请输入用户名"
read username
if ! grep $username /path/to/userfile; then
echo "无效的用户"
else
echo "欢迎您 $username"
fi
# 显示书籍清单
cat /path/to/bookfile | column -t
# 添加新书
while true; do
echo "请输入要添加的新书的标题"
read title
echo "请输入作者"
read author
echo "请输入出版社"
read publisher
echo "请输入价格"
read price
echo "$title\t$author\t$publisher\t$price" >> /path/to/bookfile
done
# 查找书籍
echo "请输入书名或者作者"
read search_term
cat /path/to/bookfile | grep $search_term | column -t
# 修改书籍
echo "请输入书名"
read book_title
echo "请输入要修改的内容"
read update_content
sed "/$book_title/s/$update_content/" /path/to/bookfile
# 删除书籍
echo "请输入书名"
read delete_book
sed "/$delete_book/d" /path/to/bookfile
# 清空库存
rm /path/to/bookfile
# 退出系统
echo "退出成功"
fi
请根据实际场景修改相应的路径和内容,运行以上脚本即可在终端上构建图书管理系统。