巴什 - for循环的目录中的每个文件夹,不包括其中的一些 [英] Bash - for-loop for every folder in a directory, excluding some of them
问题描述
非常感谢您提前帮助!
我在bash这个code:
在this_folder D / *
做
插件= $($基名D)
回声$插件?
阅读$插件
DONE
这就像一个魅力。关于'this_folder'内的每个文件夹,回声它作为一个问题和输入存储到具有相同名称的变量。
但现在我想排除某些文件夹,因此,例如,它会要求在该目录中的每个文件夹,只有当他们没有任何下列文件夹:全球,插件和CSS
任何想法我怎么能做到这一点?
谢谢!
更新:
这是最后的code的样子:
基地=coordfinder | editor_and_options |国际|陀螺仪| movecamera |方向| SA> vt_conf.sh
回声#==========基地>> vt_conf.sh
在$ orig_include / @($基地)D
做
插件= $($基名D)
回声$ =插件Y>> vt_conf.sh
DONE
呼应''>> vt_conf.sh
回声#==========可选>> vt_conf.sh
在$ orig_include D /!($基地)
做
插件= $($基名D)
回声$插件= n的>> vt_conf.sh
DONE
如果您有最新的bash的版本,你可以使用扩展的水珠(禁用了javascript -s extglob
)
在this_folder D /(全球|插件| CSS)!
做
插件= $($基名D)
回声$插件?
阅读$插件
DONE
Thank you very much in advance for helping!
I have this code in bash:
for d in this_folder/*
do
plugin=$(basename $d)
echo $plugin'?'
read $plugin
done
Which works like a charm. For every folders inside 'this_folder', echo it as a question and store the input into a variable with the same name.
But now I'd like to exclude some folders, so for example, it will ask for every folder in that directory, ONLY if they are NOT any of the following folders: global, plugins, and css.
Any ideas how can I achieve this?
Thanks!
UPDATE:
This is how the final code looks like:
base="coordfinder|editor_and_options|global|gyro|movecamera|orientation|sa"
> vt_conf.sh
echo "# ========== Base" >> vt_conf.sh
for d in $orig_include/@($base)
do
plugin=$(basename $d)
echo "$plugin=y" >> vt_conf.sh
done
echo '' >> vt_conf.sh
echo "# ========== Optional" >> vt_conf.sh
for d in $orig_include/!($base)
do
plugin=$(basename $d)
echo "$plugin=n" >> vt_conf.sh
done
If you have a recent version of bash, you can use extended globs (shopt -s extglob
):
for d in this_folder/!(global|plugins|css)
do
plugin=$(basename $d)
echo $plugin'?'
read $plugin
done
这篇关于巴什 - for循环的目录中的每个文件夹,不包括其中的一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!