Help with rm command
Hi,
I am running following command to process some files and move them into separate directory for dos2unix purpose. I am unable to remove file without prompt Command used for a in /mnt/chroot/emr/OUT/Log/* ; do zip /mnt/chroot/emr/OrderProcessed/ReceivedFiles.zip $a ; dos2unix -n $a /mnt/chroot/emr/REJ/`basename $a` ; rm –f $a ; done I am getting following resulted adding: mnt/chroot/emr/OUT/Log/LAB_LAB01332_20130418_10.HL7 (deflated 62%) dos2unix: converting file /mnt/chroot/emr/OUT/Log/LAB_LAB01332_20130418_10.HL7 to file /mnt/chroot/emr/REJ/PROGNOCIS_LAB_LAB01332_20130418_10.HL7 in UNIX format ... rm: cannot lstat `.f': No such file or directory rm: remove regular file `/mnt/chroot/emr/OUT/Log/LAB_LAB01332_20130418_10.HL7'? n adding: mnt/chroot/emr/OUT/Log/LAB_LAB01333_20130418_10.HL7 (deflated 62%) dos2unix: converting file /mnt/chroot/emr/OUT/Log/LAB_LAB01333_20130418_10.HL7 to file /mnt/chroot/emr/REJ/LAB_LAB01333_20130418_10.HL7 in UNIX format ... rm: cannot lstat `.f': No such file or directory rm: remove regular file `/mnt/chroot/emr/OUT/Log/LAB_LAB01333_20130418_10.HL7'? n Please help. |
Easier to read if you use code tags https://www.linuxquestions.org/quest...do=bbcode#code and multiple lines
Code:
for a in /mnt/chroot/emr/OUT/Log/* When interpreted by bash its comes out as '.', basically a font issue. Also, best to use $(...) instead of backquotes. http://wiki.bash-hackers.org/syntax/expansion/cmdsubst |
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 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' As demonstrated too, it's generally better to store fixed data strings in variables first, if this isn't just a one-off. |
All times are GMT -5. The time now is 06:52 AM. |