I've tried various solutions to move a file name with spaces and nothing seems to work. I need to take a date as input, prepend it to a filename with spaces then remove the spaces and mv the file to the new name.
space_test 20180419
date 20180419
oldfile 20180419_test with space.txt
newFILE 20180419_test_with_space.txt
mv: cannot stat ��: No such file or directory
I've also tried using awk to add single or double quotes around the original file name.
the echo shows the single or double quotes around the file name but I still get the same error on the mv.
oldfile 20180419_test with space.txt
origfile "20180419_test with space.txt"
oldfile 20180419_test with space.txt
origfile '20180419_test with space.txt'
I've also tried escaping the spaces with a \ but so far nothing that I've tried has worked. I get the same error. From the command line the mv works using ' or " or escaping the space with \.
In your first code sample, origFile is unset, thus empty, and mv doesn't find anything and complains as posted.
A caveat: the single quotes in the mv error message seem to be locale dependent - make sure you use ASCII characters for any input.
And, you might want to learn about shells' "parameter expansion / pattern substitution" to eliminate the sed stuff.
The {origFILE} on the mv was a cut and paste issue from trying different commands. With the mv command as
echo " "
mv "${oldFile}" "${newFILE}"
I receive
mv: cannot stat ��: No such file or directory
For the space substitution I've also tried tr, rename, and doing it in the mv command (mv "$oldFILE" "${oldFILE// /_}"). I will look where you suggested to see if there's other options I haven't tried yet.