0

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?

Shravani
  • 1,622
  • 2
  • 11
  • 16

1 Answers1

1

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
NoDataFound
  • 11,381
  • 33
  • 59