Shell 脚本中的嵌套 If 语句
这是我的脚本:
echo "Name"
read name
if [ "$name" == "abcd" ]; then
echo "Password"
read password
if [ "$password == "pwd" ]; then
echo "Hello"
else
echo "Wrong password"
fi
else
echo "wrong username"
fi
这是我运行它时得到的输出:
sh hello.sh Name abcd hello.sh: line 14: unexpected EOF while looking for matching `"' hello.sh: line 16: syntax error: unexpected end of file
知道这里出了什么问题吗?这可能是一个非常愚蠢的问题,但我在上面浪费了将近一个小时。
This is my script:
echo "Name"
read name
if [ "$name" == "abcd" ]; then
echo "Password"
read password
if [ "$password == "pwd" ]; then
echo "Hello"
else
echo "Wrong password"
fi
else
echo "wrong username"
fi
And this is the output I get when I run it:
sh hello.sh Name abcd hello.sh: line 14: unexpected EOF while looking for matching `"' hello.sh: line 16: syntax error: unexpected end of file
Any idea whats wrong here? This could be a very silly one, but i wasted almost an hour on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您在
$password
之前有一个不匹配的"
You have an unmatched
"
before$password
您可以使用
case
。这是一个例子。出于安全原因,您不会想告诉任何人哪个组件出了问题。you can use
case
. Here's an example. You won't want to tell anybody which component is wrong, for security reason.在 Shell 脚本中。
In Shell script.