2013-07-05 27 views
0

下面是我的代码片段,我试图输出一个文件名在两端都有双引号。如何在kornshell中的变量空格中加上双引号

#!/usr/bin/ksh 
....... 
##the value is: Site Information_2013-07-05-00-01-26.CSV 
RemoteFile=$(grep "$File" "$TempLog") 


##then Im trying to redirect it to a file so that it will have double quotes 
echo "\"$RemoteFile\"" > cmd 

##I'm expecting below output. 
"Site Information_2013-07-05-00-01-26.CSV" 

##instead, the double quote is missing at the end, can someone point out what I'm doing wrong 

"Site Information_2013-07-05-00-01-26.CSV 

谢谢。

+0

您的代码很好,所以在您没有向我们展示的内容中存在问题。 –

+0

即使'echo \“$ RemoteFile \”'也足够了。 – devnull

+0

只是为了实验 - 什么会'回声'\“$ RemoteFile \”\“”> cmd'返回? –

回答

0

TempLog包含以回车符结尾的行。 2个解决方案

dos2unix "$TempLog" 
sed -i 's/\r$//' "$TempLog" 

双引号缺少末,因为之后的“V”是有回车的“光标”回移到行的开头。然后打印报价,覆盖第一个字符(这也恰好是一个报价)。

+0

谢谢,实际上我发布了2个,因为我正在寻找每个解决方案来传递预期的空间,或者我只是通过变量来完成。任何这一点都解决了。谢谢 – turf

相关问题