【发布时间】:2020-06-18 14:05:30
【问题描述】:
我是使用 Bash 编写脚本的新手,我正在做一个创建库存系统的任务。我已经编写了所有脚本,它们都使用标准输入终端工作。我现在希望从名为 a1Input.txt 的文本文件中获取输入,该文件的所有输入都位于新行上。
r
9823
r
5430
c
7777
sml_widget
Small Widget (1 oz.)
6.99
15
50
Small, white, widget w/o packaging
r
7777
d
9823
r
9823
r
3293
u
3293
29.99
33
75
r
3293
我最初的 bash 脚本的代码是这样的
#!/bin/bash
# assign1.bash
shopt -s nocasematch
option=""
until [ "$option" = "F" ]; do
echo "C - create a new item"
echo "R - read an existing item"
echo "U - update an existing item"
echo "D - delete an existing item"
echo "T - total price of an item"
echo "Choose a option"
read option
case $option in
C)
./create.bash
;;R)
./read.bash
;;U)
./update.bash
;;D)
./delete.bash
;;T)
./total.bash
;;*)
echo "Invalid input"
esac
done
【问题讨论】:
-
..... esac done <a1Input.txt? bashfaq how to read a file line by line -
你什么时候收到
q: Command not found.?您是否编辑了文件并尝试使用:!q退出(应该是:q!)?还是脚本名为q而你在命令行中给出了q(应该是./q)?
标签: bash text-files stdin