conditional binary operator expected
81
- You're missing
$
in front of var when you call it, like you wrote it, it will be literallyvar
. - Consider possible vulnerabilities of your script when using
[[ ... ]]
or(( ... ))
together with variables you cannot control. In your case, it might be better to use[ "$var" -ne 0 ]
. - You're missing a space between
!=
and0
(this is the source of the error!) -
!=
is a string comparison operator, while it might work in your example, you want to use-ne
to compare integers.
Make use of shellcheck.
Related videos on Youtube
![JayminLimbachiya](https://i.stack.imgur.com/wN5AG.jpg?s=256&g=1)
Author by
JayminLimbachiya
Updated on September 18, 2022Comments
-
JayminLimbachiya almost 2 years
I want to modify reset password link. I dont want to modify vendor file.
For example: I receive link from email: http://localhost:8000/password/reset?51e5bd40dab074e8975100a2e84c08f457ec54c4cf6e0349fbe07ff67978793f
Needs to be change: http://localhost:8000/password/reset?token=51e5bd40dab074e8975100a2e84c08f457ec54c4cf6e0349fbe07ff67978793f&[email protected]
How it is possible?
Thanks in advance
-
Stéphane Chazelas about 4 yearsNote that
(( var !=0 ))
would also work here, but like[[ "$var" -ne 0 ]]
would be an arbitrary command injection vulnerability if the nature of the output of the command being captured is not under your control. -
Stéphane Chazelas about 4 yearsIn
[[ $var -ne 0 ]]
(with or without the quotes, the quotes being not necessary in this particular case) or(( var!=0 ))
, the contents of$var
is evaluated as an arithmetic expressions and bad things can happen then.[ "$var" -ne 0 ]
(the quotes being necessary here as[
is an ordinary command) is safe inbash
(but not all other shells), as$var
is interpreted as a decimal integer only.[ "$var" != 0 ]
(or the[[ $var != 0 ]]
kshism) is safe as well but would return true if$var
contains00
as it's a string comparison.