Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

File1: Binary operator expected

I am trying to create a shell script as below on Linux.

#!/bin/bash
if [ cp file1 /tmp ];
then
  rm file1
fi

But I am getting an error message as "file1:binary operator required"
I have tried a lot of options like enclosing line 2 within [[ ]], () etc but it’s not working. I am not sure what am I missing. I even tried searching for other similar questions on StackOverflow but none are solving my problem.

So can you please help?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should write:

#!/bin/bash
if cp file1 /tmp ; then
  rm file1
fi

Or

cp file1 /tmp && rm file1

Or perhaps directly:

mv file1 /tmp
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading