Hi,
I wanted to run find . -type f -exec gcp --backup=numbered "{}" tmp \;
in one instance of command.
I used \ to espace \ and ". Did I do it wrong?
I wrote:
let find_command = Command::new("find")
.current_dir(target_folder_path)
.args( &[".", "-type", "f","-exec","gcp","--backup=numbered","\"{}\"","tmp","\\;"])
.output()
It complied but has error while executing the command. The error is about ; not found. I also break it down into serval arguments such as
args(..)
arg("\"{}\"")
arg("tmp")
arg("\\;")
Then it shown a different error about backslash.
Edit 1: Something I forgot to mention. I also printed the args along as &[".", "-type", "f","-exec","gcp","--backup=numbered","\"{}\"","tmp","\\;"]
with the formatter {:#?}
. It shows the escape character. I don't now if the formatter chose to print it or I didn't escape it properly.
How can I fix this?
Thank you for replying in advance.
Solution:
Both quotes and backslash in "{}"
and \;
are not part of the argument but served as escaping in Bash.
The correct way to write is following:
.args( &[".", "-type", "f","-exec","gcp","--backup=numbered","{}","tmp",";"])