当前位置: 技术问答>linux和unix
AWK 奇怪问题!
来源: 互联网 发布时间:2014-12-10
本文导语: 执行如下脚本: find /mnt/adshel/wwwroot -type d|nawk ' NR=2 { print "#"NR; print "acl (""$0"/");"; print "deny (write,execute,delete,list,info) "; print " (user = "anyone");"; print ""; next; } ...
执行如下脚本:
find /mnt/adshel/wwwroot -type d|nawk '
NR=2
{
print "#"NR;
print "acl (""$0"/");";
print "deny (write,execute,delete,list,info) ";
print " (user = "anyone");";
print "";
next;
}
'> acl.conf
后,察看生成的 acl.conf 文件,发现如下格式:
#1
#It is a file to forbid the list file!
/mnt/adshel/wwwroot/alwin_backup
#2
acl ("/mnt/adshel/wwwroot/alwin_backup/");
deny (write,execute,delete,list,info)
(user = "anyone");
/mnt/adshel/wwwroot/alwin_backup/jsp
#3
acl ("/mnt/adshel/wwwroot/alwin_backup/jsp/");
deny (write,execute,delete,list,info)
(user = "anyone");
我的问题是, #2,#3 上面的那一条语句为什么会打出来?实在是没有道理啊!
find /mnt/adshel/wwwroot -type d|nawk '
NR=2
{
print "#"NR;
print "acl (""$0"/");";
print "deny (write,execute,delete,list,info) ";
print " (user = "anyone");";
print "";
next;
}
'> acl.conf
后,察看生成的 acl.conf 文件,发现如下格式:
#1
#It is a file to forbid the list file!
/mnt/adshel/wwwroot/alwin_backup
#2
acl ("/mnt/adshel/wwwroot/alwin_backup/");
deny (write,execute,delete,list,info)
(user = "anyone");
/mnt/adshel/wwwroot/alwin_backup/jsp
#3
acl ("/mnt/adshel/wwwroot/alwin_backup/jsp/");
deny (write,execute,delete,list,info)
(user = "anyone");
我的问题是, #2,#3 上面的那一条语句为什么会打出来?实在是没有道理啊!
|
对不起,搞错了。真正的原因是因为你的条件判断NR>=2之后的左大括符要和NR>=2应该在同一行,而不是另起一行。如下
NR>=2{
print "#"NR;
...
man 页中有如下提示:
The opening brace ``{'' must be on the same line as the pattern for which the actions should be performed. Multiple action statements may appear on a single line if they are separated by semicolons ``;''.
NR>=2{
print "#"NR;
...
man 页中有如下提示:
The opening brace ``{'' must be on the same line as the pattern for which the actions should be performed. Multiple action statements may appear on a single line if they are separated by semicolons ``;''.