-->
Perl脚本明显的可以分为两大类:一类是通过终端与实际用户进行交互的程序;另一类是仅仅与其他程序进行通信而不使用终端的程序。下面我们写一个脚本来测试脚本的交互性。脚本内容如下:
#!/usr/bin/perl -w
if(-t STDIN){
print "终端输入\n";
}else{
print "非终端输入
";
}
if(-t STDOUT){
print "终端输出\n";
}else{
print "非终端输出
";
}
以下是脚本的运行结果:
[root@supersun terminal]# perl terminaltest.pl
终端输入
终端输出
[root@supersun terminal]# ls |perl terminaltest.pl
非终端输入
终端输出
[root@supersun terminal]# perl terminaltest.pl >c
[root@supersun terminal]# cat c
终端输入
非终端输出
[root@supersun terminal]# ls |perl terminaltest.pl >cc
[root@supersun terminal]# cat cc
非终端输入
非终端输出
看到这里之后也许你能明白什么叫“与终端交互”了吧!

发表评论