简体   繁体   English

回声输出未正确格式化

[英]echo output not formatting properly

I am trying to setup a script to build expect commands to run inline with that script based on data i have pulled from elsewhere. 我正在尝试设置一个脚本来构建expect命令,以便根据我从其他地方提取的数据与该脚本一起内联运行。

I need the output to look like this 我需要输出看起来像这样

send "get filename1.out.dat.pgp\n"
expect "sftp>"
send "get filename2.out.dat.pgp\n"
expect "sftp>"

I am using the following code 我使用以下代码

while read filel
do
    echo 'send "get '${filel}'\n"' >> $ExpectCMMDSGET
    echo 'expect "sftp>"' >> $ExpectCMMDSGET
done < "$DirList"

but when i cat the file out i get 但当我把文件拿出来的时候我得到了

\n"d "get filename1.out.dat.pgp
expect "sftp>"
\n"d "get filename2.out.dat.pgp
expect "sftp>"

and when i look at in VI i get 当我看到VI时,我得到了

send "get filename1.out.dat.pgp^M\n"
expect "sftp>"
send "get filename2.out.dat.pgp^M\n"
expect "sftp>"

I have tried using sed to remove the ^M once the file is created before being used but it is not working. 我曾尝试使用sed在使用之前创建文件后删除^ M但它无法正常工作。

Any suggestions 有什么建议么

It sounds like "$DirList" contains carriage returns. 听起来像"$DirList"包含回车符。 You can use sed -i "s/\\r//g" file to delete them from a file, preferably from your original input, but alternately from your created file. 您可以使用sed -i "s/\\r//g" filesed -i "s/\\r//g" file中删除它们,最好是从原始输入中删除它们,但也可以从创建的文件中删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM