0

I'm using the following bash script on a mac to rename files using a list of file names. It works and doesn't throw an error but when it's finished all the files (which are images) have a question mark following the extension and don't know what application they need to use to open. This does not happen when I manually type in mv oldName.TIF newName.TIF into the command line. Help?

#!/bin/bash

printf "%s\n" *.TIF | paste - names.txt | while IFS=$'\t' read -r old new; 
do
    mv "$old" "$new";
done
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Have you made a dry-run of the script to see what the commands it'll actually use to rename the files? You could replace `mv "$old" "$new";` with `echo mv "$old" "$new";` - or do `set -x` in the script – Ted Lyngmo Jan 24 '22 at 00:14
  • Is your `names.txt` file in DOS/Windows format (see ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings)), or have some other sort of weird formatting/invisible characters? – Gordon Davisson Jan 24 '22 at 05:43

1 Answers1

2

I think I might have figured it out. It seems like the problem is running it on a directory that is on a flash drive. When I transfer the folder to my hard drive and run the script it works fine.