当我在tcl中使用它时,awk bash命令会出错

时间:2015-10-19 11:52:03

标签: tcl

当我运行命令

awk '/^proc/ {print $2}' <file_name>

在bash中我没有问题。但是当我在Tcl脚本中使用exec函数作为

时使用它

exec awk "/^proc/ {print $2}" win_test.tcl

我接受error can't read "2": no such variable

1 个答案:

答案 0 :(得分:3)

使用单引号括起exec命令,然后使用set awkCmd {/^proc/ {print $2}} exec awk $awkCmd <file-name>

[dinesh@mypc mypgms]$ cat sample.tcl
proc Hello {} {
}

proc World {} {
}

[dinesh@mypc mypgms]$ tclsh
% set awkCmd {/^proc/ {print $2}}
/^proc/ {print $2}
% exec awk $awkCmd sample.tcl
Hello
World
%    

示例

var Progressajax2 = false;
$(document).ready(function() {
    $(".closeclass").on('click',function() {

        if(Progressajax2)
            return;
        Progressajax2 = true;

        var element = $(this);
        var I = element.attr("id");
        var value = element.attr("value");

        var pagecont = $('.pagecont'+value).val();
        var contcomments = $('.contcomments'+value).text();
        if(confirm('Are you sure?')) {

            $.ajax({
                type: "POST",
                url: "/delete.php",
                data: "id="+I,
                success: function() {
                    Progressajax2 = false;

                    pagecont = parseInt(pagecont)-parseInt(1);
                    contcomments = parseInt(contcomments)-parseInt(1);
                    $('.pagecont'+value).val(pagecont);
                }
            });
        }
    });
});