如何在bash脚本中处理查找结果?

我试图使用一个数组来存储使用find命令的文件名列表。

由于某种原因,数组无法在学校使用的bash工作,我的程序工作在我自己的笔记本电脑上。

所以我想知道是否有另一种方式来做,这就是我所拥有的:

array = (`find . -name "*.txt"`)  #this will store all the .txt files into the array

然后我可以访问数组项,并使用cat命令制作所有文件的副本。

有没有另外一种方式来做,而不使用数组?

你可以使用这样的东西:
find . -name '*.txt' | while read line; do
    echo "Processing file '$line'"
done

例如。制作副本:

find . -name '*.txt' | while read line; do
    echo "copying '$line' to /tmp"
    cp -- "$line" /tmp
done

HTH

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...