KSH:-eq和=之间的差异(KSH: diference between -eq and =)
假设我有这个小程序:
until [ "$name" = "$secretname" ] do read name done而不是使用=,如果我使用-eq它仍然有效。
是否有理由在“-eq”上使用“=”
Let say I have this small program:
until [ "$name" = "$secretname" ] do read name doneInstead of using =, if i used -eq it still works.
Is there a reason for using the "=" over the "-eq"
最满意答案
-eq仅用于比较整数。 它将忽略前导零:
$ test 09 -eq 9 && echo match || echo no match match如果参数不是整数,它也会报告错误:
$ test abc -eq abc && echo match || echo no match bash: test: abc: integer expression expected no match=用于比较任意字符串
$ test abc = abc && echo match || echo no match match $ test 09 = 9 && echo match || echo no match no match-eq is only for comparing integers. It will ignore leading zeroes:
$ test 09 -eq 9 && echo match || echo no match matchIt will also report an error if the arguments are not integers:
$ test abc -eq abc && echo match || echo no match bash: test: abc: integer expression expected no match= is for comparing arbitrary strings
$ test abc = abc && echo match || echo no match match $ test 09 = 9 && echo match || echo no match no match更多推荐
发布评论