我想在awk脚本中更改工作目录:

  ...
  path="./some/path"
  system("pwd") ; \
  current_dir=system("pwd") ; \
  pushd_cmd="pushd " path ; \    # a "cd" doesn't work too
  print pushd_cmd ; \
  system(pushd_cmd) ; \
  system("pwd"); \               # the same directory as before
  type="xml"
  ls_cmd = "ls *." type;         # so I can't find the files. Specifying with "./some/path/*.xml" doesn't work too (without trying to change the working directory)
  ...

有人知道为什么系统对我的情况没有影响吗?

最佳答案

system将启动子进程,子进程不能更改其父进程的工作目录。
快速的Google搜索显示了GNU AWK文档的以下部分:http://www.delorie.com/gnu/docs/gawk/gawk_252.html
这似乎意味着标准AWK没有改变工作目录的方法。(在GNU AWK中,您可以使用chdir来完成它,如您所见。)

关于bash - 在脚本中awk更改工作目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12313895/

10-11 22:05
查看更多