您的位置:首页 > 运维架构 > Shell

awk内部调用外部shell命令

2011-01-04 15:12 519 查看
Reference:http://www.computing.net/answers/unix/awk-command/6949.html

awk uses the system function to execute any OS command, and the
return code can be captured and checked, as shown below. You can also
read in all the output of a system call (very handy).

When I check
the code returned from the OS, zero means success. But within awk, a
zero expression means false and non-zero means true. If you run the
code below, you will see that "one means true".

awk 'BEGIN {
rc=system("test -f myfile")
if (rc==0)
print "exists"
else
print "does NOT exist"
if (system("test -f myfile"))
print "does NOT exist"
else
print "exists"
if (0)
print "zero means true"
if (1)
print "one means true"
exit}'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: