Ubuntu 14.04 Cron输出以^ M结尾的文件名 [英] Ubuntu 14.04 Cron outputs file names with ^M at the end

查看:58
本文介绍了Ubuntu 14.04 Cron输出以^ M结尾的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用>运算符将输出通过管道传输到cron作业中的文件时,它总是在文件名的末尾附加一个^ M.这显示为?当我在目录中运行ls时,当我在nano中编辑文件并保存时,其自身显示为^ M.

When I pipe output to a file in a cron job using the > operator, it always appends a ^M to the end of the file name. This shows up as a ? when I run ls in the directory but reveals itself as ^M when I edit the file in nano and go to save.

例如以下命令:

locale > locale.txt

输出名为"locale.txt?"的文件(即"locale.txt ^ M")

Outputs a file named "locale.txt?" (i.e. "locale.txt^M")

我不知道为什么要这么做,但是我猜想它与环境变量有关.当我从终端使用>时,它的行为正常.我已经在Google上搜索了此问题,但显然它不喜欢查询中的所有这些特殊字符,因此我什么也没找到.

I don't know why it does this, but I'm guessing it has something to do with environment variables. When I use > from a terminal it behaves properly. I've searched Google for this problem but apparently it doesn't like all these special characters in the query so I haven't found anything.

我尝试使用mv将文件名恢复为正常,但无法识别?或在输入文件名时输入^ M字符.

I've tried using mv to change the file name back to normal but it doesn't recognize the ? or the ^M character when I type in the file name.

我已经看到也许这是回车符"\ r",但是我不知道为什么cron会在文件名的末尾添加Windows换行符.感谢所有帮助.谢谢!

I've seen that perhaps this is the carriage return "\r" character but I don't know why cron would put a Windows newline on the end of my file name. All help is appreciated. Thanks!

推荐答案

问题出在cron或脚本文件本身:它具有DOS行分隔符(CRLF),而不是Unix(仅适用于LF).您可以使用 dos2unix 对其进行修复.

The problem is with the cron or script file itself: it has DOS line separators (CRLF) instead of Unix (LF only). You can fix it using dos2unix.

这篇关于Ubuntu 14.04 Cron输出以^ M结尾的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆