目录中每个文件夹的 for 循环,不包括其中一些 [英] for-loop for every folder in a directory, excluding some of them

查看:36
本文介绍了目录中每个文件夹的 for 循环,不包括其中一些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢您的帮助!

我在 bash 中有这个代码:

I have this code in bash:

for d in this_folder/*    
    do    
        plugin=$(basename $d)
        echo $plugin'?'
        read $plugin
    done

这就像一个魅力.对于this_folder"中的每个文件夹,将其作为问题回显并将输入存储到同名变量中.

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.

但现在我想排除一些文件夹,例如,它会询问该目录中的每个文件夹,前提是它们不是以下任何文件夹:global、plugins 和 css.

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?

谢谢!

更新:

最终代码如下:

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

推荐答案

如果你有最新版本的 bash,你可以使用扩展的 globs (shopt -s extglob):

If you have a recent version of bash, you can use extended globs (shopt -s extglob):

shopt -s extglob

for d in this_folder/!(global|plugins|css)/   
do    
    plugin=$(basename "$d")
    echo $plugin'?'
    read $plugin
done

这篇关于目录中每个文件夹的 for 循环,不包括其中一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆