Cp: missing file operand

Why cp: missing file operand? What "cp" parameter i need to add or whats wrong please?

domlistexp=domlistexp
domlistexp_bak=domlistexp_bak
touch $domlistexp
rm -rf $domlistexp_bak
cp $domlistexp $domlistexp_bak

output:

+ rm -rf domlist_bak
+ cp
cp: missing file operand
Try `cp --help' for more information.

Please put code and/or output in CODE tags. It makes it much easier to read.

domlistexp=domlistexp
domlistexp_bak=domlistexp_bak
touch $domlistexp
rm -rf $domlistexp_bak
cp $domlistexp $domlistexp_bak

output:
+ rm -rf domlist_bak
+ cp
cp: missing file operand
Try `cp --help' for more information.

I must say that it works fine for me on the ksh command line (HP-UX 11.11, AIX 5.1 and RHEL 6.3)

It works fine if I put it in a script and call it with ksh -x myscript too:-

hp8:/home/RBATTE1> cat myscript 
domlistexp=domlistexp
domlistexp_bak=domlistexp_bak
touch $domlistexp
rm -rf $domlistexp_bak
cp $domlistexp $domlistexp_bak

hp8:/home/RBATTE1> ls -l dom*
dom* not found

hp8:/home/RBATTE1> ksh -x myscript 
+ domlistexp=domlistexp
+ domlistexp_bak=domlistexp_bak
+ touch domlistexp
+ rm -rf domlistexp_bak
+ cp domlistexp domlistexp_bak
hp8:/home/RBATTE1> ls -l dom*
-rw-------   1 RBATTE1    users            0 Dec  2 12:00 domlistexp
-rw-------   1 RBATTE1    users            0 Dec  2 12:00 domlistexp_bak
hp8:/home/RBATTE1>

Can you elaborate a little? How are you running it?

Robin
Liverpool/Blackburn
UK

Are you sure you have the right variable names?

Your trace output doesn't exactly match what your example code should produce (there is no domlist_bak ).

1 Like

yes, im sure, i checked many times

As Carlos opinted, this:

output:
+ rm -rf domlist_bak

Is quite confusing, since its not what you show in first part of code...
Since, it seems that your rm was void, the file $domlistexp_bak still present leading a cp messages "missing operand" ( since file exist it needs a -f ...)

1 Like

Thank you, i think it was an undefined variable that i tried to use. (i mean i called $variable , but not defined it before).

SOLVED

thx all who tried to help