Please Help Me "Binary Operator Expected in Cygwin"

Please Help me binary operator expected in cygwin

the script is probably using '#!/bin/sh' but expects the behaviour of /bin/bash. Try executing the script as: /bin/bash shell_script.sh

debugging tools include executing the script with the -x option, i.e. bash -x shell_script.sh. The problem from the outset looks like an unset variable that is being checked using the unprotected form:

if [ $x = ]

the problem is that if $x is unset, then you end up with an empty token, which causes the script to fail.

for the explicit 'clear' command not found, the cygwin implementation of that is to call 'tput clear' if you replace the 'clear' call with 'tput clear' then it should work.

[[ operator fails with error conditional binary operator expected

The mv command shouldn't be inside the conditional expression, it's a command that you want to execute depending on the result of the condition. It should be

[[ -f file1.txt ]] && mv file1.txt file1_old.txt

Also, don't put it inside double parentheses, that's for arithmetic expressions, not commands.

unary operator expected error in Bash if condition

If you know you're always going to use Bash, it's much easier to always use the double bracket conditional compound command [[ ... ]], instead of the POSIX-compatible single bracket version [ ... ]. Inside a [[ ... ]] compound, word-splitting and pathname expansion are not applied to words, so you can rely on

if [[ $aug1 == "and" ]];

to compare the value of $aug1 with the string and.

If you use [ ... ], you always need to remember to double quote variables like this:

if [ "$aug1" = "and" ];

If you don't quote the variable expansion and the variable is undefined or empty, it vanishes from the scene of the crime, leaving only

if [ = "and" ];

which is not a valid syntax. (It would also fail with a different error message if $aug1 included white space or shell metacharacters.)

The modern [[ operator has lots of other nice features, including regular expression matching.

error C2679: binary '' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Have you included all of the following headers?

  • <fstream>
  • <istream>
  • <iostream>
  • <string>

My guess is you forgot <string>.

On a side note: That should be std::cout and std::endl.

conditional binary operator expected in shell script

Problem is in your if [[...]] expression where you are using 2 grep commands without using command substitution i.e. $(grep 'pattern' file).

However instead of:

if [[ grep $check_val1 $log -ne $check_val1 || grep $check_val2 $log -ne $check_val2 ]]; then

You can use grep -q:

if grep -q -e "$check_val1" -e "$check_val2" "$log"; then

As per man grep:

-q, --quiet, --silent
Quiet mode: suppress normal output. grep will only search a file until a match
has been found, making searches potentially less expensive.


Related Topics



Leave a reply



Submit