[英]Loop through Filenames with spaces Bash using variables
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
Appreciate help on this.. 对此有帮助。
Looks to me like the whole loop ought to be mkdir -p "$File_Directory"
... 在我看来,整个循环应该是
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. 但是,使用参数解析的确确实有点麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.