system只能对命令的输出结果输出到终端。
getline在awk中可以使命令的输出结果传到一个变量中保存。
# awk 'BEGIN{system("date")|getline out;print out}'Sun Jan 1 22:11:58 CST 2017sh: 1: 0: not found # awk 'BEGIN{"date"|getline out;print out}'Sun Jan 1 22:13:47 CST 2017 # awk 'BEGIN{system("date")}'Sun Jan 1 22:16:10 CST 2017 # awk 'BEGIN{system("ls")}' ali.txt a.log_bk awk_file b.txt dir1 exe.shell f1.txt_bk f2.txt_bk filename func learn_shell_bk newfile t xarg.txt a.log a.txt awk_files dir exe1.shell f1.txt f2.txt f3.txt fir.txt learn_shell learn_shell.save sec.txt text # awk 'BEGIN{"ls"}' # awk 'BEGIN{"ls" | getline out;print out}' ali.txt