SSS
SSS

Reputation: 51

[[ operator fails with error "conditional binary operator expected"

Linux bash script fails for the following line. Error message as given. I know i can simply use if [ -f file1.txt ] but curious to know what needs to be fixed to make this working.

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

conditional binary operator expected expected `)'

Upvotes: 0

Views: 612

Answers (1)

Barmar
Barmar

Reputation: 780994

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.

Upvotes: 1

Related Questions