Friday, 23 August 2013

Ubuntu - "mv" command renames file to empty file name

Ubuntu - "mv" command renames file to empty file name

I have a simple script to move files between directories. Basically, it is:
mv /dir/* /dir/proc/
saved into a shell script "mvproc.sh".
For some reason, when I run the script (sh mvproc.sh) the file indeed gets
moved, but it does not retain the filename and instead gets just an empty
filename. When I run the same command at the bash prompt, it works fine
however.
This script used to work fine on Debian but we had a hard drive failure
and I am now migrating everything over to a Ubuntu machine.
Any idea why this is happening? It seems so simple yet I cannot figure it
out.
Many thanks.
edit...
I think I found the solution. For some reason it was putting in carriage
returns and maybe line breaks or something that I could not see while
editing the sh script in either Notepad++ or even gedit. To solve this,
when I open the scripts in gedit, I do a Save As, and select Unix/Linux in
the drop down menu towards the bottom. This hopefully gets rid of the
weird carriage returns even though I could not see them.
Hopefully this helps some poor soul like me in the future pulling their
hair out over this!
Thanks!

No comments:

Post a Comment