"找不到命令"试图在bash整数平等时, [英] "Command not found" when attempting integer equality in bash
本文介绍了"找不到命令"试图在bash整数平等时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,这可能会是超明显,任何人花了更多的时间使用bash,比我有。
Ok, this is probably going to be ultra obvious to anyone that has spent more time with bash than I have.
我试图运行此code:
I'm trying to run this code:
#!/bin/bash
if ["1" -eq "2"]
then
echo "True"
else
echo "False"
fi
但是当我执行这个文件,它发回
but when I execute the file, it sends back
./test.sh: line 3: 1: command not found
False
有一定有什么重大的我失踪。我见过的人使用分号括号后,这似乎没有任何区别...:•
There must be something major I'm missing. I've seen people use a semicolon after the brackets, this doesn't seem to make any difference... :S
推荐答案
是的EQ仅用于算术comparaisons。
yep eq is used only for arithmetic comparaisons.
对于字符串比较,你必须使用 =
for string comparison you have to use =
#!/bin/bash
if [ "1" = "2" ]
then
echo "True"
else
echo "False"
fi
再加上你需要周围的括号一些空间。
plus you need some space around the brackets.
这篇关于"找不到命令"试图在bash整数平等时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文