本文介绍了目录中每个文件夹的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.

任何想法如何实现?

谢谢!

更新:

这是最终代码的样子:

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,则可以使用扩展的glob(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循环,其中不包括其中一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:37