开发者

Appending to file in bash loop is adding ^M

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开发者_Python百科$file\n" >> $log_file
  cat $file >> $output_file
done


you can always do a dos2unix on your files before processing.


For the record and for googlers, this arises most commonly from Windows line endings. Use nix line endings for your script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜