bash - awk 在脚本中更改工作目录

标签 bash unix awk system pwd

我想在 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.gnu.org/software/gawk/manual/html_node/Internal-File-Description.html#Internal-File-Description

这似乎暗示标准AWK 没有改变工作目录的方法。 (在 GNU AWK 中,您可以使用 chdir 来实现。)

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

相关文章:

bash - 使用大括号参数列表多次执行命令

arrays - Bash 多个命令行参数

bash - 在 Bash 中访问间接 shell 变量

linux - 如何在 Unix 中合并同一个文本文件中的多行

如果 ping 服务器关闭,Linux 命令在服务器上生成文件,如果服务器启动,则生成不同的文件

linux - 无法使用 awk 中的系统导出变量

linux - 将一组命令输出存储到 shell 变量会引发错误

linux - 如何使用 xargs 和 cat 将两个不同文件的内容作为参数进行管道传输?

c - 这是在忙着等待吗?

bash - awk 提示命令中来自连接字符串的非终止字符串