In addition, the variables are unquoted, so word-splitting will take place on the values, if they contain whitespace.
And there's no need for
basename at all, when we can use
parameter substitution.
I also think it's best to use clear variable names whenever possible.
Code:
for fname in /mnt/chroot/emr/OUT/Log/* ; do
zip /mnt/chroot/emr/OrderProcessed/ReceivedFiles.zip "$fname"
dos2unix -n "$fname" "/mnt/chroot/emr/REJ/${fname##*/}"
rm -f "$fname"
done
Frankly though, I'm not sure I quite understand the command flow here. First you archive the files,
then you convert them into unix line ending format (while copying them to a new directory), and finally you remove the originals? I guess it's ok, but it seems a bit odd to me.
Actually, it seems to me that the loop is unnecessary. You should be able to use direct
globbing with all the commands.
Code:
filepath='/mnt/chroot/emr/OUT/Log'
copypath='/mnt/chroot/emr/REJ'
zipfile='/mnt/chroot/emr/OrderProcessed/ReceivedFiles.zip'
zip "$zipfile" "$filepath/"*
cp "$filepath/"* "$copypath"
rm -f "$filepath/"*
dos2unix "$copypath/"*
The only things this assumes are that "$copypath" only holds the copied files (or that it's safe to run dos2unix on the other files in it), and that the number of files is low enough not to overflood the system's ARG_MAX value.
As demonstrated too, it's generally better to store fixed data strings in variables first, if this isn't just a one-off.