awk判断文件是否存在
时间:2010-11-23 来源:ccjsj1
整理了几个:
1、
[neo]$ awk 'BEGIN{a=system("test -f /etc/passwdd");if(a) {print "file not exist!";exit}}{print $1}' /etc/passwd
file not exist! 2、 [neo]$ awk 'BEGIN{if(system("test -f /etc/passwdd")) {print "file not exist!";exit}}{print $1}' /etc/passwd
file not exist! 3、 [neo]$ awk 'BEGIN{if((getline<"/etc/passwdd")==-1) {print "file not exist!";exit}}{print $1}' /etc/passwd
file not exist! 4、 [neo]$ awk '{"[ -e /etc/passwdd ]&&echo 1||echo 0"|getline a;if(!a) {print "error";exit}}{print $1}' /etc/passwd
error
file not exist! 2、 [neo]$ awk 'BEGIN{if(system("test -f /etc/passwdd")) {print "file not exist!";exit}}{print $1}' /etc/passwd
file not exist! 3、 [neo]$ awk 'BEGIN{if((getline<"/etc/passwdd")==-1) {print "file not exist!";exit}}{print $1}' /etc/passwd
file not exist! 4、 [neo]$ awk '{"[ -e /etc/passwdd ]&&echo 1||echo 0"|getline a;if(!a) {print "error";exit}}{print $1}' /etc/passwd
error
相关阅读 更多 +