Zsh – Excluding Files from a Pattern in Zsh

shell-scriptwildcardszsh

Say I have the following files:

|-- bar
`-- foo
    |-- type_A_1
    |-- type_A_2
    |-- type_B_1
    |-- type_B_2
    |-- type_B_xx
    |-- type_B_xx
    `-- something_else

I thought the following command

print -l foo/*~{type_B*}

would print everything under foo except things that start with type_B but it doesn't, instead it prints everything under foo:

foo/type_A_1
foo/type_A_2
foo/type_B_1
foo/type_B_2
foo/type_B_xx
foo/something_else

I also tried print -l foo/*~type_B and got the same thing.

How does the exception wildcard ~ work in zsh?

Best Answer

You need to include the directory into the exception: print -l foo/*~foo/type_A* or print -l foo/*~{foo/type_A*}.

If you want, you can replace the directory by a wildcard: print -l foo/*~*/type_A*

Related Question