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 `)’
Advertisement
Answer
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.