gpt4 book ai didi

unix - 在子目录中执行命令

转载 作者:行者123 更新时间:2023-12-04 04:54:07 25 4
gpt4 key购买 nike

我想为存在于不同子目录中的文件运行程序,然后将输出重定向到输出文件。我希望将输出保存到程序运行的目录中。

所以我想做这样的事情:

for x in */*.txt; do command $x > output.fsa; done

我的问题是:
  • 上面的循环正确吗?我应该更改目录以将输出保存在执行命令的目录中还是由 linux 处理?
  • 关于如何在输出文件中给出目录名称的任何想法?
  • 最佳答案

    Is it correct the above loop?



    是的

    should I change directory in order to save the output on the directory that the command was executed or linux takes care of it?



    您不需要更改目录,只需将输出重定向到正确目录中的文件即可:
    for x in */*.txt; do command $x > `dirname $x`/output.fsa; done

    关于unix - 在子目录中执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17019724/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com