Reputation: 2393
I'm running a Bash script that loops through the files in a directory and appends them all to a single file.
However, I find that ^M is being added to the end of every line.
The original files do not contain this escape character and manually appending the files on the command line does not insert the character.
I don't know if it matters, but I'm using eval to construct and then retrieve the directory names as below:
Construct directory names:
declare ${schema}_${type}_${subtype}="$(eval echo \$${schema}_${type}_${subtype}) $(echo $file | egrep -v "$excluded_types" | grep $schema/$type/$subtype)"
Retrieve directory names:
for file in $(eval echo \$${schema}_${type}_${subtype})
do
echo -e "\t\t\t$file"
echo -e "\t\t\t$file\n" >> $log_file
cat $file >> $output_file
done
Upvotes: 1
Views: 1386
Reputation: 9685
For the record and for googlers, this arises most commonly from Windows line endings. Use nix line endings for your script.
Upvotes: 0