lundi 19 juin 2017

How to check and use the status of cp command in shell script?

This is a statement in my shell script. ${origin} and ${archive} are 2 directories.

The command reads all jpg, png and jpeg files within the ${origin} folder and copy them to ${archive} folder.

find ${origin} -regex '.*\(jpg\|png\|jpeg\)' -exec cp -n {} ${archive} \;

What I want is that if cp successfully copy a file, ( also indicates that the file does not exist in ${archive} folder), it will execute some commands.

Questions:

  1. How can I know whether cp successfully copy the file, in the shell script?

  2. Where can I place the if statement?

Aucun commentaire:

Enregistrer un commentaire