【发布时间】:2012-10-14 21:49:26
【问题描述】:
我想比较用户在这个文本文件中输入的内容,以确定他们输入的内容是否在文本文件中,然后告诉他们。
file1: color_readme.txt 在这个文件中是:
red
red
orange
blue
代码:
echo Please enter a color:
cat color_readme.txt (printing the colors to screen)
read userinput (read what the user enters)
variable1 = grep $userinput (a random variable = what is found in the file according to what the user typed)
if userinput = variable1 (SAY THIS)
else (SAY THIS)
对于初学者来说,最好的方法是什么? 我的老师只希望我使用基本的 ifelse 和 else 条件。
【问题讨论】:
-
帮助我们和您用伪语言(或英语)解释您想要做什么,而不是编写难以理解的代码。谢谢。
-
为什么是截图而不是实际代码?
-
这不是代码,这是 bash 和虚构代码的混合体。
-
不难理解;很难复制和编辑。如果您正在寻求帮助,您应该让人们轻松地为您提供帮助。
-
用英语提出真正的问题肯定比显示损坏的代码更好。