從 Unix 命令列進行臨時資料分析/附錄
外觀
一個 perl 讀取-求值-列印迴圈。這在命令列上建立了一個非常方便的計算器。示例用法
$ pcalc 1+2 3 $ pcalc "2*2" 4 $ pcalc 2*3 6
來源
#!/opt/third-party/bin/perl
use strict;
if ($#ARGV >= 0) {
eval_print(join(" ",@ARGV))
} else {
use Term::ReadLine;
my $term = new Term::ReadLine 'pcalc';
while ( defined ($_ = $term->readline("")) ) {
s/[\r\n]//g;
eval_print($_);
$term->addhistory($_) if /\S/;
}
}
sub eval_print {
my ($str) = @_;
my $result = eval $str;
if (!defined($result)) {
print "Error evaluating '$str'\n";
} else {
print $result,"\n";
}
}
太好的想法,不能刪除,但還沒有完善。
示例 - 哪個 .so 包含我想要的物件?
kill `ps auxww | grep httpd | grep -v grep | awk '{print $2}'`
tail -f `ls -rt *log | tail -1`
James 使用 echo 與 xargs 並以巧妙的方式將一個 xargs 的輸出饋送到另一個 xargs,以構建複雜的命令列。