红联Linux门户
Linux帮助

perl脚本中的system grep

发布时间:2011-08-03 15:12:03来源:红联作者:年年年
在perl脚本中我要用到系统命令,
通过system()可以完成。
但是当我写到:
$str=system ("tail -f /tmp/test.log |grep -E aaa|bbb");
时候它提示aaa|bbb中的“|bbb”不是bash命令。。。
它把或看成管道了。。
我改成:
$str=system ("tail -f /tmp/test.log |grep -E "aaa|bbb"");
或者:
$str=system ("tail -f /tmp/test.log |grep -E (aaa|bbb)");
等都不行。
请问应该怎样才能达到目的?求高手指教。。
文章评论

共有 4 条评论

  1. 木子leal 于 2011-08-08 09:53:36发表:

    :0wszxc

  2. 年年年 于 2011-08-04 09:39:33发表:

    3# 奶茶dsk


    谢谢奶茶!双引号加上反斜杠就可以了。。

  3. 奶茶dsk 于 2011-08-03 19:27:10发表:

    引用:
    $str=system ("tail -f /tmp/test.log |grep -E aaa|bbb");

    没用过perl,,应该差不多,

    $str=system ("tail -f /tmp/test.log |grep \"aaa\\|bbb\"");
    或者
    $str=system ("tail -f /tmp/test.log |grep -E \"aaa|bbb\"");

    都试试吧

  4. sy20577037 于 2011-08-03 15:50:30发表:

    ding