我在编写用于检查文本文件以查看其中是否存在的“ For Loop”语句时遇到麻烦

时间:2019-04-14 19:54:26

标签: linux bash shell

我正在编写“ for loo”语句,该语句检查测试文件以查看是否输入了多个参数。我编写的脚本会返回所有内容,即使它不存在

for i in "$@"
do
grep -q "$i" /home/s132a18/A10/cisStudents  && echo "$i is a student" || echo "$i is not a student"

done

1 个答案:

答案 0 :(得分:0)

当单词not是唯一的区别时:

for i in "$@"
do
   echo "$i is $(grep -q "$i" /home/s132a18/A10/cisStudents || echo "not ")a student"
done