awk内部调用外部shell命令

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}'

你可能感兴趣的:(linux)