Bash 如何使用“查找”获取上次找到的文件夹的名称`

Bash 如何使用“查找”获取上次找到的文件夹的名称`,bash,Bash,我有一个包含多个组件的文件夹结构: src-/ |-components-/ |-componentA |-componentB |-componentC 我想找到每个组件文件夹,对其执行命令,并使用文件夹名称作为我的dist/目录中每个输出文件夹的名称。所以它应该是这样的: dist-/ |-componentA |-componentB |-compo

我有一个包含多个组件的文件夹结构:

src-/
    |-components-/
                 |-componentA
                 |-componentB
                 |-componentC
我想找到每个组件文件夹,对其执行命令,并使用文件夹名称作为我的
dist/
目录中每个输出文件夹的名称。所以它应该是这样的:

dist-/
     |-componentA
     |-componentB
     |-componentC
当前我正在运行以下命令:

BABEL_ENV=cjs find src/components/**-type d-exec BABEL{}--out dir dist/{}\

但是,这给出了
{}
中的完整文件路径,因此结果如下:

src/components/componentA/index.js->dist/src/components/componentA/index.js

我希望结果是:

src/components/componentA/index.js->dist/componentA/index.js

我怎样才能做到这一点


提前感谢

请尝试以下操作:

while read -r -d "" path; do
    basename=${path##*/}    # will remove "src/components/" portion
    BABEL_ENV=cjs babel "$path" --out-dir "dist/$basename"
done < <(find src/components/* -type d -print0)
读取-r-d”路径时;做
basename=${path##*/}#将删除“src/components/”部分
BABEL_ENV=cjs BABEL“$path”--out dir“dist/$basename”
完成<