Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash - For each directory in a folder, make a directory within a different location

Tags:

bash

I have a directory which contains several folders. I'd like to make a bash script to create directories with the same name in a different location.

Note that I don't want to copy the folder structure, neither copy or move the folders. I just want to create folders with the same name in a different location.

I'm stuck. Using this:

for d in "template/modules/*"
do
    # mkdir $(basename "$d");
    echo $d;
    echo "$d";
    echo $(basename "$d");
done

Output:

template/modules/introduction template/modules/kitchen template/modules/test
template/modules/*
add_module.sh template

Any ideas?

Cheers

like image 580
RafaelGP Avatar asked Sep 18 '25 23:09

RafaelGP


1 Answers

You need to put the asterisk outside the quotes:

for d in "template/modules/"*

In the first echo, $d is expanded, but when you quote it, it's not.

like image 153
l0b0 Avatar answered Sep 22 '25 07:09

l0b0