The Carriage Return character is \r (0x0D), the CR character moves the cursor to the beginning of the line without advancing to the next line.
When you get the file location read from a file and if you use in while functionality, will get carriage return character so that you couldn't get exact path instead fo you get output with CR character (\r).
log_file="logfiles.txt"
cat $log_file | while read line; do
echo $line
echo "Downloading - $line"
done
Just run the Bash script with an option -x you will get the full output of the script.
$ sudo bash -x script.sh
Then, You can trim that character using sed command see the script below,
log_file="logfiles.txt"
cat $log_file | while read line; do
echo $line
echo "Downloading - $line"
c_path=$(echo $line | sed -e 's/\r//g')
done
Comments (0)