【问题标题】:An sh syntax errorsh 语法错误
【发布时间】:2011-10-11 04:59:06
【问题描述】:

我正在执行这个字符串,它实际上不是下面的内容,它是使用系统在 C++ 中生成的。

   /root/sendEmail -t me -f me -u 'Report ' -m 'List:
    Process id:26783 Cpu usage:52.8 Command:perl-ewhile(2) {print 9}
    Process id:3535 Cpu usage:23.6 Command:konsole [kdeinit] -session 10c579426f000130356953700000033
    Process id:2428 Cpu usage:0.513 Command:postgres: wal writer process
    Total cpu usage:78.5

Regards
Your  program
' -s 192.168.0.11

我收到一个错误 h:-c:第 0 行:在寻找匹配的 `'' 时出现意外的 EOF sh:-c:第 2 行:语法错误:文件意外结束 怎么了?我只知道如果命令为空,我不会收到此错误。

【问题讨论】:

  • 你必须用反斜杠转义你的换行符。
  • 你能告诉我们这个sendEmail的内容吗?
  • NO,我没有,这几天我没有这个错误,我不确定是什么改变了..它似乎没有任何意义
  • 您可以接受自己的答案并获得声望积分。祝你好运!

标签: c++ linux sh


【解决方案1】:

字符串包含导致它的acii代码为0的字符。

【讨论】:

    【解决方案2】:

    如果您在命令中使用换行符,则需要使用 \ 转义它们 所以:

    /root/sendEmail -t me -f me -u 'Report ' -m 'List:\
        Process id:26783 Cpu usage:52.8 Command:perl-ewhile(2) {print 9}\
        Process id:3535 Cpu usage:23.6 Command:konsole [kdeinit] -session 10c579426f000130356953700000033\
        Process id:2428 Cpu usage:0.513 Command:postgres: wal writer process\
        Total cpu usage:78.5\
    
    Regards\
    Your  program\
    ' -s 192.168.0.11
    

    【讨论】:

    • 不,你不需要\。它被引用了。
    • 哦,不知道。对不起。
    猜你喜欢
    • 2016-05-30
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多