BASH: create an array of all directory names in a directory that does NOT have a specific pattern in the name

I have a directory containing a bunch of .zip files as well as an unpacked version of them. I need to get a list of all directories and ignore the .zip files. How can i do this?

I am thinking of using grep

and ls

, but I'm not sure how.

+3


source to share


2 answers


Get a list of all subdirectories and store them in an array:



shopt -s nullglob
dirs=( */ )

      

+5


source


If you can include extglob

like this:

shopt -s extglob
declare -a files=( !(*.zip) )

      



Learn more about bash pattern matching on the pattern matching page .

+5


source







All Articles