Using parameter expansion to generate arguments list for `mkdir -p`
setopt histsubstpattern extendedglob
mkdir -p /tmp/foo/*(#q/:s_%_/bar_)
This is extended globbing that has a q
uiet glob flag that uses a glob qualifier to match only directories and a modifier to perform a s
ubstitution (using the %
pattern character that is only available in history substitution pattern mode) that appends a string to each word.
man zshexpn
Sure - use a loop
for n in /tmp/foo/*; do mkdir "$n/bar";done
globs are used to expand lists of existing items, not things which have not yet been created.
If the directories are in an array, you can use the ${^...}
form of expansion.
a=(/tmp/foo/*/)
mkdir -p ${^a}bar