With zsh
, you can do:
(){ mkdir $^@/yo; } /home/karan/P*(/)
(where $^array
turns on rcexpandparam
(for rc
-style array expansion) for the expansion of $array
only, and the expansion of that glob (here with a /
glob qualifier to restrict to files of type directory) is turned into the $@
array through the use of an anonymous function).
Or you could do:
mkdir /home/karan/P*(/e:REPLY+=/yo:)
(using the e
valuate glob qualifier to append a /yo
to matching files).
Or:
set -o histsubstpattern
mkdir /home/karan/P*(/:s:%:/yo)
(using the :s/string/replacement/
csh-style modifier to add /yo
in that case. With histsubstpattern
, the string
is interpreted as a pattern and like in ksh's ${var/pattern/replacement}
, a leading %
means the pattern is anchored at the end of the subject)
With rc
or derivatives:
dirs = ( /home/karan/P*/ )
mkdir $dirs^yo
es
, one of those rc
derivatives also has anonymous functions like zsh
above, though with a different syntax:
@ {mkdir $*^yo} /home/karan/P*/
With fish
:
set dirs /home/karan/P*/
mkdir ${dirs}yo
With ksh93 or bash (or zsh), you could always do:
dirs=(/home/karan/P*/)
mkdir "${dirs[@]/%/yo}"
Or with any shell and GNU xargs
:
printf '%syo\0' /home/karan/P*/ | xargs -r0 mkdir
(beware that the expansion of P*/
(as opposed to zsh
's P*(/)
) would also include symlink to directories. In zsh
, replace the /
glob qualifier with -/
if its actually what you want).