error `conditional binary operator expected` in compound branch

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am running such a program:
min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi
It report error
$ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'
I have examined carefully line-by-line.
What might be the problem?
bash
add a comment |Â
up vote
0
down vote
favorite
I am running such a program:
min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi
It report error
$ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'
I have examined carefully line-by-line.
What might be the problem?
bash
1
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am running such a program:
min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi
It report error
$ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'
I have examined carefully line-by-line.
What might be the problem?
bash
I am running such a program:
min_val=1
max_val=100
int=50
if [[ "$int" =~ ^-?[0-9]+$ ]]; then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
echo "$int is within $min_val to $max_val."
else
echo "$int is out of range."
fi
else
echo "int is not an integer." >&2
exit 1
fi
It report error
$ bash test_integer3.sh
test_integer3.sh: line 12: conditional binary operator expectedtest_integer3.sh:
line 12: syntax error near `"$max_val"'test_integer3.sh:
line 12: ` if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then'
I have examined carefully line-by-line.
What might be the problem?
bash
edited Apr 3 at 5:43
asked Apr 3 at 5:29
JawSaw
29410
29410
1
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35
add a comment |Â
1
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35
1
1
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
You will have to compare against $int in both comparisons:
if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then
or,
if (( int >= min_val )) && (( int <= max_val )); then
add a comment |Â
up vote
4
down vote
Your -le doesn't have a left operand.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
You will have to compare against $int in both comparisons:
if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then
or,
if (( int >= min_val )) && (( int <= max_val )); then
add a comment |Â
up vote
2
down vote
accepted
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
You will have to compare against $int in both comparisons:
if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then
or,
if (( int >= min_val )) && (( int <= max_val )); then
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
You will have to compare against $int in both comparisons:
if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then
or,
if (( int >= min_val )) && (( int <= max_val )); then
if [[ "$int" -ge "$min_val" && -le "$max_val" ]]; then
You will have to compare against $int in both comparisons:
if [[ "$int" -ge "$min_val" ]] && [[ "$int" -le "$max_val" ]]; then
or,
if (( int >= min_val )) && (( int <= max_val )); then
answered Apr 3 at 5:44
Kusalananda
102k13201317
102k13201317
add a comment |Â
add a comment |Â
up vote
4
down vote
Your -le doesn't have a left operand.
add a comment |Â
up vote
4
down vote
Your -le doesn't have a left operand.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Your -le doesn't have a left operand.
Your -le doesn't have a left operand.
answered Apr 3 at 5:39
user1934428
35119
35119
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435193%2ferror-conditional-binary-operator-expected-in-compound-branch%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Add a shebang and then paste your script there: shellcheck.net
â Cyrus
Apr 3 at 5:35