I have a shell script that moves files from a source directory to a working directory where the files are processed (used to populate an Oracle database), then moves them to an archive directory. All of the files end with a file extension that's equal to the year and week (e.g.this week would be 201524) that we refer to as the cycle. Occasionally, duplicate files are transferred to the source directory after they have already been processed before. This is all done through an automated process in production over which we have no control, other than modifying the shell script. My current attempt at the script is something like this -
mv /working/*.* /archive
mv /source/newfiles.* /working
cycle=`sqlplus -S user@prod/password << EOF
select substr(max(filename,instr(max(filename,'.',-1) + 1) ==> this gets the extension
where status = 'Completed'; ==> means file has already been processed
grep -c $cycle /working/*.* ==> searched for files with extensions that were already processed
if [ $exit_code -eq 0 ] ==> means file that files were found
mv -f /working/*.$cycle /archive ==> this is where the problem is
If I echo "mv -f /working/*.$cycle /archive", it comes out as
mv -f /working/*.
It creates a new line
I have also tried creating a variable for each part of the string with the $cycle and concatenating the variables into another variable, but I then get a space instead of the linefeed between the mv -f /working/*. and the $cycle
Can anyone show me how to concatenate strings with variables without breaks of any kind?