I'm getting some very strange behaviour that I can't figure out when trying to read a txt file.
I have a txt file that looks like this:
98040520
98041022
98041024
...
And then I have a bash script with some basic debugging that looks like this:
#!/usr/bin/env bash
while read id; do
test=123
echo "${test}.png"
echo $id
echo "${id}.png"
echo "test${id}.png"
exit
done <myfile.txt
And the output is
123.png
98040520
.png
.png98040520
What on earth is going on?
It prints "98040520" just fine, but it won't print "98040520.png", it just prints the ".png" part and an attempt to print "test98040520.png" results in the id being appended creating ".png98040520" and the word "test" excluded altogether!!
I figure it's got to be something to do with line endings (the txt file comes from windows) but I haven't been able to find anything online that will help. I've been searching for how to trim whitespace or line endings which may mean i've been looking for the wrong thing.
In case it's not clear what i'd like to do is get "98040520.png" or more specifically filepath=../../path/to/my/dir/98040520.png but what i've posted above is a simpler example of the problem I seem to be having.