How to generate list of directories and execute actions for each item in the list?

1

I'm trying to build a Shell Script that stores the directories that exist in the / Volumes root and perform an iteration over these, ignoring only the directory: "Preboot" and "Macintosh H"

    
asked by anonymous 30.09.2017 / 00:10

1 answer

0

Quick response

for d in /Volumes/*; do
  if [ "$d" != "/Volumes/Preboot" -a "$d" != "/Volumes/Macintosh H" ]; then
    itera "$d";
  fi;
done

Explanation

for will iterate over a set of given words. In this case, we are passing /Volumes/* , which will be subjected to a glob expansion, and therefore the iteration argument of for will be all non hidden content of /Volumes .

In condition, I am making sure that the $d variable is neither the Preboot folder within /Volumes nor Macintosh H within /Volumes as well. I can not remember any membership operations in test . You could have used case/esac also to ignore these options.

The test cmd1 -a cmd2 , in particular -a , is the and operation of the test command. By way of example, the example operation at the beginning of this paragraph is true if cmd1 and cmd2 are true.

Disclaimer

As I am without a computer, I was in doubt when the glob expansion generates options with spaces in the middle, but I believe that even if this generates a bug in the code, it is almost trivial to fix it.     

30.09.2017 / 02:24