Why is this for loop removing the first one or two characters of a file path?

1

I am trying to find all *.flac files in a directory tree, encode them with ffmpeg, and then output them to a corresponding tree in another location. I am using Cygwin on Windows 10. This is what I have so far:

$ find /cygdrive/d/Users/Drew/Music/beets/Music -type f -name '*\.flac' > files
$ while read line; do ffmpeg -i "$line" -f null "$(echo $line | sed 's/\.flac/\.mp3/' | sed 's/Music\/beets/Desktop/')"; done < files

The first command has generated a good list of files (that I can tell), but the while loop gives ffmpeg errors every other file due to the leading '/' being trimmed:

cygdrive/d/Users/Drew/Music/beets/Music/$uicideboy$/Eternal Grey/06 Uglier.flac: No such file or directory

and occasionally another error seemingly randomly when 2 characters are trimmed:

Parse error, at least 3 arguments were expected, only 1 given in string 'ygdrive/d/Users/Drew/Music/beets/Music/$uicideboy$/Eternal Grey/08 Elysian Fields.flac'

Is there some newline problem going on here that I can not detect? Is it something else? Why is this happening?

Drew

Posted 2019-02-19T07:08:29.097

Reputation: 29

Does it work with read -r? http://mywiki.wooledge.org/BashFAQ/001

– slhck – 2019-02-19T08:53:54.787

2

Does this answer your question? 'while read' loop through lines in text file losing characters in Bash script. is FFmpeg line to blame?

– Kamil Maciorowski – 2019-12-31T23:39:11.577

No answers