how do you assign the filenames in the directory to the according filenames in names.txt? Simply by the position in the "ls" output?
In this case you can do it like this:
1. create a file with the filename's list:
2. merge the two files:
paste /tmp/list.txt /tmp/names.txt
You get the following 2 column output:
jan@jack:~/tmp> paste -d " " /tmp/list.txt /tmp/names.txt
3. Now you can use this output to rename the files:
paste -d " " /tmp/list.txt /tmp/names.txt | while read line; do
The filenames may not contain spaces or tabs!