虽然我已经使用 BASH 好几年了,但我在 BASH 脚本方面的经验相对有限。
我的代码如下。它应该从当前目录中获取整个目录结构并将其复制到$OUTDIR
.
for DIR in `find . -type d -printf "\"%P\"\040"`
do
echo mkdir -p \"${OUTPATH}${DIR}\" # Using echo for debug; working script will simply execute mkdir
echo Created $DIR
done
Run Code Online (Sandbox Code Playgroud)
问题是,这是我的文件结构示例:
$ ls
Expect The Impossible-Stellar Kart
Five Iron Frenzy - Cheeses...
Five Score and Seven Years Ago-Relient K
Hello-After Edmund
I Will Go-Starfield
Learning to Breathe-Switchfoot
MMHMM-Relient K
Run Code Online (Sandbox Code Playgroud)
请注意空格 :-S 并for
逐字接受参数,因此我的脚本输出如下所示:
Creating directory structure...
mkdir -p "/myfiles/multimedia/samjmusicmp3test/Learning"
Created Learning
mkdir …
Run Code Online (Sandbox Code Playgroud)