我想从键盘格式中插入多个名称:
A
B
C
我尝试使用while
这样的循环:
name=$*
while [ "$name" != "done" ]
do
echo "name:"
read $name
echo "$name"
done
当我插入"done"
时,它将完成循环并将所有名称写入文本文件
答案 0 :(得分:0)
使用SELECT `rt`.`name`, AVG(`rg`.`rating`) AS `rating`
FROM `restaurant` `rt`, `rating` `rg`
LEFT JOIN `rg`.`restaurant` = `rt`.`id` GROUP BY `rg`.`restaurant`
并从stdin读取有什么问题?
cat
您可以将输出重定向到文件并使用cat -
<Ctrl-D>
答案 1 :(得分:0)
这是你要找的吗?
#!/bin/bash
while true
do
read -p "Enter line : " line
if [[ $line = "done" ]]
then
exit -1
#-1 to show abnormal input ie "done"
else
echo "$line" >> file #appending what you entered using >>
fi
done
或者惯用:
#!/bin/bash
cat /dev/null > file #Emptying file if already exist
while read -p "Enter line : " line && [[ $line != "done" ]]
do
echo "$line" >> file
done