I want copy some files, but I want to wait executing the copy commands untill the end of the script. The reason for this is I can expect a user input to interrupt the script halfway, and I don't won't a partially copied directory.
Is there any way I can wait to execute specific commands until exit 0
is seen in the same program?
#!/bin/bash
for f in 'find something/ -newer something_else -type f'; do
#Expecting user input interruption
cp "$f" . #I want to wait executing this
done
if [ -f something_else ]; then
exit 0 #I want it executed here
else
exit 1
fi
exit 1
is potentially executed? Also, don't loop over the result offind
, and remember to double-quote your variable expansions. – Kusalananda Mar 03 '18 at 12:11