I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the files (and only those two) being purged and replaced by link ../../modules/[name_of_file]
.
APPFOLDER="/home/opt/ke"
CMD_APPCOPY="cp -fr _opt/ke/* $APPFOLDER"
[...]
echo "copying app-files to app-folder $APPFOLDER ..."
eval $CMD_APPCOPY
if [ $? -ne 0 ] ; then
echo "could not copy app-files to app-folder $APPFOLDER"
exit
fi
If I start the file copy by hand everything is fine.
cp -fr _opt/ke/* /home/opt/ke
But if I run the script the two files will be empty except for the link ../../modules/[name_of_file]
part added on top of the empty file.
The two files in question are neither very huge or very small in size, the only thing that differentiate them from the other files in that directory is that they are of the Perl-Module .pm type. Their actual source destination is /home/xxx/xxx/deploy/KEB/_opt/ke/modules/
while the full target destination is /home/opt/ke/modules/
. The script and the manual copy are run from /home/xxx/xxx/deploy/KEB/
of course.
Any idea/advice how this behaviour could be explained or what I should be looking for in order to fix the script is very much appreciated.
eval echo $CMD_APPCOPY
. You should use an array to store a command:CMD_APPCOPY=(cp -fr _opt/ke/* $APPFOLDER); "${CMD_APPCOPY[@]}"
(reference)*
does not expand within double quotes. So that's wrong to start with.cp -fr _opt/ke/cache _opt/ke/conf _opt/ke/modules _opt/ke/scripts _opt/ke/t /home/opt/ke
and unfortunately switching to array storing didn't have any effect.eval
? Can you not just run that variable as$CMD_APPCOPY
.