[英]Wget on Linux saves files differently if called from the command line vs running from a script
I use wget to download a file to my server.我使用 wget 将文件下载到我的服务器。
When I paste this in the terminal command line: wget 'https://www.example.com/export/komatsu/komatsu_export.php?pass=Kowa444m11008&date=month' -O /root/workingdir/KOWA_SampleResult_ZAF_ date +"%Y%m%d"
.csv当我将其粘贴到终端命令行时:wget 'https://www.example.com/export/komatsu/komatsu_export.php?pass=Kowa444m11008&date=month' -O /root/workingdir/KOWA_SampleResult_ZAF_
date +"%Y%m%d"
.csv
it saves the file as KOWA_SampleResult_ZAF_20221215.csv它将文件保存为 KOWA_SampleResult_ZAF_20221215.csv
But when I paste the same line into a.sh file and run the file eg sh kowa_automate.sh但是当我将同一行粘贴到 a.sh 文件并运行文件时,例如 sh kowa_automate.sh
it saves the file as 'KOWA_SampleResult_ZAF_20221215.csv'$'\r'它将文件保存为 'KOWA_SampleResult_ZAF_20221215.csv'$'\r'
Why the discrepancy with the extra symbols: ' '$'\r'为什么与额外符号不一致:' '$'\r'
Andrew安德鲁
I tried running the script bash kowa_automate.sh.我尝试运行脚本 bash kowa_automate.sh。
The issue was that Linux interprets Windows created text files differently.问题是 Linux 对 Windows 创建的文本文件的解释不同。 Windows new lines include CR LF, whereas Linux only uses LF.
Windows 新行包括 CR LF,而 Linux 仅使用 LF。 Hence the \r.
因此\r。
If in a text editor such as notepad++ on windows;如果在 windows 上的记事本++等文本编辑器中; you must use the EOL conversion to Unix.
您必须使用 EOL 转换为 Unix。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.