You'll need to put quotes around the string when you use it for the ls and the move command:
for file in "$(ls -t | tail -n +1)"
do
mv "$file" /tmp/test
done
Try that.
Longer explanation:
When you look closely at the output of your example, you see that the interpreter tries three times:
first it tries to move the file 'Sublime'
Then it tries to move the file 'Text'
and lastly it tries to move the file '3.x'
The hint you may pick up is that they are separated by a space. You are able to move three files in one go with the mv
command, but only if those files exist.
so:
mv file1.txt file2.txt file3.txt /some/destination/dir
..can be a valid command to move three files.
To prevent the interpreter to look for individual files (separated by a space) you can tell it to take the full filename (including spaces) when you surround the variable with spaces.
Good question!