gpt4 book ai didi

linux - bash 脚本运行每个文件夹

转载 作者:太空宇宙 更新时间:2023-11-04 04:47:49 26 4
gpt4 key购买 nike

我需要在每个文件夹中运行 bash 脚本,但我怎样才能做到最好?

这是需要在每个文件夹中运行的脚本我还需要跟踪文件所在的文件夹 $Title

#!/bin/bash

rm -f output2.txt
rm -f output3.txt
ls -td $PWD/test/*.pdf |head -5 >> output2.txt
ls -t test/ | sed -e 's/\.[^.]*$//' | head -5 >> output3.txt
output2=output2.txt
output3=output3.txt


download_one=$(awk 'FNR==1' $output2)
download_two=$(awk 'FNR==2' $output2)
download_three=$(awk 'FNR==3' $output2)
download_four=$(awk 'FNR==4' $output2)
download_five=$(awk 'FNR==5' $output2)

download_one_title=$(awk 'FNR==1' $output3)
download_two_title=$(awk 'FNR==2' $output3)
download_three_title=$(awk 'FNR==3' $output3)
download_four_title=$(awk 'FNR==4' $output3)
download_five_title=$(awk 'FNR==5' $output3)

rm -f output2.txt
rm -f output3.txt

Title=
Title2=$Title

echo $Title,$Title2,$download_one_title,$download_one,$download_two_title,$download_two,$download_three_title,$download_three,$download_four_title,$download_four,$download_five_title,$download_five >> test.csv

第二个错误

    /home/intranet/script: line 5: /home/intranet/test/test1/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test1/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test1/script: No such file or directory
ls: cannot access /home/intranet/test/test1/test/*/*.pdf: No such file or directory
ls: cannot access test/: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test2/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test2/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test2/script: No such file or directory
ls: cannot access /home/intranet/test/test2/test/*/*.pdf: No such file or directory
ls: cannot access test/: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test3/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test3/script: No such file or directory
/home/intranet/script: line 5: /home/intranet/test/test3/script: No such file or directory
ls: cannot access /home/intranet/test/test3/test/*/*.pdf: No such file or directory
ls: cannot access test/: No such file or directory

第二个代码

    #!/bin/bash

curdir=$(pwd)
for folder in /home/intranet/test/*; do
[ -d $folder ] && cd "$folder" && $curdir/script
done
cd $curdir

rm -f output2.txt
rm -f output3.txt
ls -td $PWD/test/*/*.pdf |head -5 >> output2.txt
ls -t test/ | sed -e 's/\.[^.]*$//' | head -5 >> output3.txt
output2=output2.txt
output3=output3.txt


download_one=$(awk 'FNR==1' $output2)
download_two=$(awk 'FNR==2' $output2)
download_three=$(awk 'FNR==3' $output2)
download_four=$(awk 'FNR==4' $output2)
download_five=$(awk 'FNR==5' $output2)

download_one_title=$(awk 'FNR==1' $output3)
download_two_title=$(awk 'FNR==2' $output3)
download_three_title=$(awk 'FNR==3' $output3)
download_four_title=$(awk 'FNR==4' $output3)
download_five_title=$(awk 'FNR==5' $output3)

rm -f output2.txt
rm -f output3.txt

Title=lol
Title2=$Title

echo $Title,$Title2,$download_one_title,$download_one,$download_two_title,$download_two,$download_three_title,$download_three,$download_four_title,$download_four,$download_five_title,$download_five >> test.csv

最佳答案

find /path/to/Files -type d -exec myscript.sh {} \;

找到正常的工作,您可以指定更多选项来过滤文件夹,例如时间或访问权限,...

关于linux - bash 脚本运行每个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24262762/

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