回声输出格式不正确
问题描述:
我想建立一个脚本来建立预期的命令与该脚本内联运行,基于我从别处拉出的数据。回声输出格式不正确
我需要的输出看起来像这样
send "get filename1.out.dat.pgp\n"
expect "sftp>"
send "get filename2.out.dat.pgp\n"
expect "sftp>"
我使用下面的代码
while read filel
do
echo 'send "get '${filel}'\n"' >> $ExpectCMMDSGET
echo 'expect "sftp>"' >> $ExpectCMMDSGET
done < "$DirList"
但是当我的猫出该文件我得到
\n"d "get filename1.out.dat.pgp
expect "sftp>"
\n"d "get filename2.out.dat.pgp
expect "sftp>"
当我看看VI我得到
send "get filename1.out.dat.pgp^M\n"
expect "sftp>"
send "get filename2.out.dat.pgp^M\n"
expect "sftp>"
我曾尝试使用sed删除^ M一旦文件被创建之前使用,但它不工作。
任何建议
答
这听起来像"$DirList"
包含回车。您可以使用sed -i "s/\r//g" file
从文件中删除它们,最好从原始输入中删除它们,但也可以从您创建的文件中删除它们。
哈哈,当然我没有想到这一点。我非常专注于输出。感谢它的魅力 – camarokris