gpt4 book ai didi

linux - 搜索一系列目录 bash 脚本

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:27 24 4
gpt4 key购买 nike

我已经(尝试)编写了这个用于搜索一系列目录的小 bash 脚本。

#!/bin/bash
shopt -s nullglob
for file in [ac]*/blarg
do
echo $file
done

此脚本在以“a”到“c”开头的目录中搜索“blarg”。它只深入一层。我怎样才能让它遍历它可能遇到的所有目录,而不仅仅是具有首字母的目录的根目录。

此外,这个问题应该放在 stackoverflow 上还是 super 用户更合适?

谢谢

最佳答案

如果你有 Bash 4.0,你可以试试 globstar

#!/bin/bash
shopt -s nullglob
shopt -s globstar
for file in [ac]*/**/blarg
do
echo $file
done

关于linux - 搜索一系列目录 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1919355/

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