Copy without overwrite in OpenWRT

Apologies for the stupid question! Does anyone know how to copy without overwriting a file in OpenWRT? The cp command in OpenWRT appears to have limited options and lacks the required option to not overwrite files!

I can easily check if the file exists in Lua, but this is yet another time consuming task that I’d prefer to avoid if the OS can do this.

Thanks
Chris

According to its --help, the cp command has the -i option. That’s the closest cp gets to “don’t overwrite”. What were you expecting?

Edit: oh, you are hoping for the GNU cp -n option. Nope, OpenWrt cp is the busybox cp, it never had all the bells and whistles of GNU.

You could string together a shell pipeline:

[ ! -e “$target” ] && cp “$source” “$target”

Thanks fuztle,
Yes, I was after the -n option. -i says it prompts for overwrite, which isn’t quite what I’m after. That said, I’ve not tried it from Lua, but I assume it will simply never return if run from os.execute().

It’s strange that there’s an “overwrite” option (-f), but cp seems to do this already by default!

Cheers
Chris

-f will overwrite a target file even if it has been marked read-only (say, with a chmod -w). Which may inspire you to an alternative approach.

Ah - thanks. At least that makes sense now and I may be able to use that to my advantage. I’ll have a play…

Cheers
Chris