如果否则判断魏德错误
无法运行代码,错误“ [[add:“
找不到)。
#!/bin/bash
add() {
first="${1}"
second="${2}"
result=`expr $first + $second`
echo "The sum of two numbers are $result"
return $result
}
subtract() {
first="${1}"
second="${2}"
result=`expr $first - $second`
echo "The sum of two numbers are $result"
return $result
}
echo "[0] Add"
echo "[1] Subtract"
read operation
echo "Enter Number One"
read first
echo "Enter Number Two"
read second
if [["$operation" == "Add"]]
then
add $first $second
else
subtract $first $second
fi
我正在尝试运行此代码,如果其他比较不起作用。每次我执行代码时,在第32行中都会发生错误并执行。我正在尝试创建一个加法/减法bash sh文件。
root@Kumaraswamy:~# ./maths.sh
[0] Add
[1] Subtract
Add
Enter Number One
7
Enter Number Two
3
./maths.sh: line 32: [[Add: command not found
The sum of two numbers are 4
root@Kumaraswamy:~#
Unable to run code, error "[[Add:"
not found.
#!/bin/bash
add() {
first="${1}"
second="${2}"
result=`expr $first + $second`
echo "The sum of two numbers are $result"
return $result
}
subtract() {
first="${1}"
second="${2}"
result=`expr $first - $second`
echo "The sum of two numbers are $result"
return $result
}
echo "[0] Add"
echo "[1] Subtract"
read operation
echo "Enter Number One"
read first
echo "Enter Number Two"
read second
if [["$operation" == "Add"]]
then
add $first $second
else
subtract $first $second
fi
I am trying to run this code, the if else comparison does not work. Each time i execute the code, at line 32 an error is occurred and else is executed. I am trying to create an addition/subtraction bash sh file.
root@Kumaraswamy:~# ./maths.sh
[0] Add
[1] Subtract
Add
Enter Number One
7
Enter Number Two
3
./maths.sh: line 32: [[Add: command not found
The sum of two numbers are 4
root@Kumaraswamy:~#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
之后留出空间[
或[[
。这应该起作用,因为这些是在环境变量$ path
下列出的目录之一中找到的真实可执行文件。Leave a space after
[
or[[
. That should work since these are real executables found in one of the directories listed under environment variable$PATH
.