我有一个用于 linux 的 shell 脚本,它位于基本级文件夹中testing
,将进入该original
目录,将所有内容复制到该input
文件夹中,然后在每个子目录中input
执行三个任务:
tip
tip
sorted
当我在命令行上测试它时,我遇到的唯一问题是,由于我tip
在将所有内容移入文件夹之前创建了该文件夹,因此它会返回一个错误,即它无法在自身内部移动文件夹——这很好,无论如何。但是,当我在 NiFi 中运行它时,它会给我一个不同的错误 ( cannot create directory tip: file exists
) 并且行为不同。
脚本
#!/bin/bash
# copy to input while maintaining file structure
cd /data/testing/original
cp -r * /data/testing/input
cd /data/testing/input
# for each subfolder in input, create tip & sorted, and move all of the original stuff into tip
for dir in /data/testing/input/*
do
test -d "$dir" || continue
cd "$dir" && mkdir tip && mv * tip/
mkdir sorted
done
中每个子文件夹中的预期输出 /data/testing/input/subfolder/
sorted -> empty
tip -> media folder, file1, file2
实际产量
sorted -> empty
tip -> media folder, file1, file2
media folder
file1
file2
我究竟做错了什么?
shopt -s extglob
# trailing slash forces the results to be dirs
# ..............................v
for dir in /data/testing/input/*/; do
(
cd "$dir" && mkdir tip sorted && mv -t tip/ !(tip|sorted)
# ..........................................^^^^^^^^^^^^^
# anything *not* matching "tip" or "sorted"
)
# run above in a subshell so you don't have to cd back to parent dir
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句