【发布时间】:2019-11-12 17:24:36
【问题描述】:
这是我的第一篇文章,所以如果我做错了什么,请让我现在!
我在 bash 中尝试在循环中使用 cp 时遇到问题,想知道是否有人可以提供帮助?我似乎无法让它找到一个绝对存在的目录
我正在尝试在一组类似的子目录路径中获取一些 .pdf 文件并将它们复制到一个易于查看的文件中。
这是我的脚本的样子:
shopt -s globstar
s_dir="C:/Bash Testing/CG SIS Standard Items"
t_dir="C:/Bash Testing/BoxFolder"
REFS=$(find "$s_dir"** -iname "*.pdf" -ipath "*/References/*" -not -ipath "*/Archive/*")
for ref in "${REFS[@]}"
do
SORTED_REFS="$SORTED_REFS $ref"
done
COPY_REFS=$( "$SORTED_REFS" | sort -u )
echo "$COPY_REFS"
for file in "$COPY_REFS"
do
cp -v "$file C:/Bash Testing/BoxFolder/" .
done
这就是我运行脚本后 GIT bash 的样子,包括 pwd & ls 的结果,这样您就可以更好地理解文件夹结构。
./script.sh: line 47: C:/Bash Testing/CG SIS Standard Items/00 General/References/CG SiS Standard Items - Material Board.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.001_Short Rail, 1368mm/References/CG.S.001_Short Rail, 1368mm.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.002_Short Base/References/CG.S.002_Short Base.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.003_Square Base/References/CG.S.003_Square Base.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.004_Long Rail, 1368mm/References/CG.S.004_Long Rail, 1368mm.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.005_Long Base/References/CG.S.005_Long Base.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.006_Short Rail, 1528mm/References/CG.S.006_Short Rail, 1528mm.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.007_Shelf Add On/References/CG.S.007_Shelf Add On.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.008_Storage Table/References/CG.S.008_Storage Table.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.009_Nesting Table/References/CG.S.009_Nesting Table.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.010_Storage Block/References/CG.S.010_Storage Block.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.011_Long Rail, 1528mm/References/CG.S.011_Long Rail, 1528mm.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.012_Wall Mounted Frame/References/CG.S.012_Wall Mounted Frame.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.013_Short Base, Slim/References/CG.S.013_Short Base, Slim.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.014_Long Base, Slim/References/CG.S.014_Long Base, Slim.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.015_Mannequin Stand/References/CG.S.015_Mannequin Stand.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.016_Accessory Unit/References/CG.S.016_Accessory Unit.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.018_End Rail/References/CG.S.018_End Rail.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.019_Tall Nesting Table/References/CG.S.019_Tall Nesting Table.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.020_End Rail Cap/References/CG.S.020_End Rail Cap.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.022_Wall Mounted Frame Rail/References/CG.S.022_Wall Mounted Frame Rail.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.023_Wall Mounted Frame Shelf/References/CG.S.023_Wall Mounted Frame Shelf.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.024_Wall Mounted Frame Top Shelf/References/CG.S.024_Wall Mounted Frame Top Shelf.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.025_Wall Mounted Frame Large/References/CG.S.025_Wall Mounted Frame Large.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.026_Wall Mounted Frame Large Rail/References/CG.S.026_Wall Mounted Frame Large Rail.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.027_Wall Mounted Frame Large Shelf/References/CG.S.027_Wall Mounted Frame Large Shelf.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.028_Wall Mounted Frame Large Top Shelf/References/CG.S.028_Wall Mounted Frame Large Top Shelf.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.029_Wall Mounted Frame Face Out Arm/References/CG.S.029_Wall Mounted Frame Face Out Arm REV 1.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.029_Wall Mounted Frame Face Out Arm/References/CG.S.029_Wall Mounted Frame Face Out Arm.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.030_Wall Mounted Frame Cabinet/References/CG.S.030_Wall Mounted Frame Cabinet.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.030_Wall Mounted Frame Cabinet/References/CG.S.030_Wall Mounted Frame Cabinet_NEW DIVIDER.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.031_Rail Face Out/References/CG.S.031_Rail Face Out REV1.pdf
C:/Bash Testing/CG SIS Standard Items/CG.S.031_Rail Face Out/References/CG.S.031_Rail Face Out.pdf: No such file or directory
cp: cannot stat ' C:/Bash Testing/BoxFolder/': No such file or directory
>> pwd
/c/Bash Testing
>> ls
{testfile}.txt} '~bash_profile' 1.txt 2.txt 3.txt 4.txt 5.txt BoxFolder/ 'CG SIS Standard Items'/ script.sh* test.sh
>> ls 'CG SIS Standard Items'
'00 Account Management'/ 'CG.S.009_Nesting Table'/ 'CG.S.022_Wall Mounted Frame Rail'/
'00 General'/ 'CG.S.010_Storage Block'/ 'CG.S.023_Wall Mounted Frame Shelf'/
'00 Item Archive'/ 'CG.S.011_Long Rail, 1528mm'/ 'CG.S.024_Wall Mounted Frame Top Shelf'/
'CG.S.001_Short Rail, 1368mm'/ 'CG.S.012_Wall Mounted Frame'/ 'CG.S.025_Wall Mounted Frame Large'/
'CG.S.002_Short Base'/ 'CG.S.013_Short Base, Slim'/ 'CG.S.026_Wall Mounted Frame Large Rail'/
'CG.S.003_Square Base'/ 'CG.S.014_Long Base, Slim'/ 'CG.S.027_Wall Mounted Frame Large Shelf'/
'CG.S.004_Long Rail, 1368mm'/ 'CG.S.015_Mannequin Stand'/ 'CG.S.028_Wall Mounted Frame Large Top Shelf'/
'CG.S.005_Long Base'/ 'CG.S.016_Accessory Unit'/ 'CG.S.029_Wall Mounted Frame Face Out Arm'/
'CG.S.006_Short Rail, 1528mm'/ 'CG.S.018_End Rail'/ 'CG.S.030_Wall Mounted Frame Cabinet'/
'CG.S.007_Shelf Add On'/ 'CG.S.019_Tall Nesting Table'/ 'CG.S.031_Rail Face Out'/
'CG.S.008_Storage Table'/ 'CG.S.020_End Rail Cap'/ 'CG.S.032_ Plinths'/
提前致谢。如果您需要更多信息,请告诉我
【问题讨论】:
标签: bash loops for-loop copy cp