使用变量循环使用空格Bash遍历文件名 [英] Loop through Filenames with spaces Bash using variables
本文介绍了使用变量循环使用空格Bash遍历文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下脚本遍历文件夹结构,但是跳过了文件夹之间的空格.
I am using the following script to iterate over a folder structure, however folders contains space in between is skipped.
for i in $(echo $File_Directory | sed "s/\// /g")
do
if [ -d $i ]
then
echo "$i directory exists."
else
echo "Creating directory $i"
`mkdir $i`
fi
done
对此有所帮助.
推荐答案
在我看来,整个循环应该是 mkdir -p"$ File_Directory"
...
但是假设他 meant 将它们全部放在同一个目录中:
Looks to me like the whole loop ought to be mkdir -p "$File_Directory"
...
But assuming he meant to put them all in the same dir:
$: File_Directory=a/b/c/d/e/f/g
$: ( IFS=/; for d in $File_Directory; do mkdir -p "$d"; done; )
尽管通过参数解析确实起到了快速而松散的作用.
That does play a little fast and loose with the parameter parsing though.
这篇关于使用变量循环使用空格Bash遍历文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文