这是我的剧本:
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
这里有什么想法吗?这可能是一个非常愚蠢的,但我浪费了将近一个小时。
答案 0 :(得分:7)
if [ "$password == "pwd" ]; then
"
$password
个匹配
答案 1 :(得分:2)
您可以使用case
。这是一个例子。出于安全原因,您不希望告诉任何人哪个组件出错。
echo "Name"
read name
echo "Password"
read password
case "${name}${password}" in
"abcdpwd" )
echo "hello";;
*) echo "User or password is wrong";;
esac
答案 2 :(得分:0)
在Shell脚本中。
nameof()
答案 3 :(得分:-1)
if [ "$name" == "abcd" ];
then
echo "Password"
read password
if [ "$password" == "pwd" ];
then
echo "Hello"
else
echo "Wrong password"
fi
else
echo "wrong username"
fi