I'm writing a bash script that needs to list all the names of folders inside a certain folder and print their description from a file inside each folder. here is a example filesystem:
main
||
\/
folder1
folder2
folder3
folder4
template
inside each folder other than main
there is a file called description
(including the template
folder), here is an example description file:
folder1
=======
contains:
* x
* y
* z
the folders might change name, more be added, and some removed. so I don't want to hardcode any number or name
I want to print all the folders and their descriptions like this using only bash and as little if any other programs (cat, grep etc. is ok) and without the template
folder:
**folder1**
folder1
=======
contains:
* x
* y
* z
**folder2**
folder2
=======
contains:
* x
* y
* z
**folder3**
folder3
=======
contains:
* x
* y
* z
**folder4**
folder4
=======
contains:
* x
* y
* z
^note that the template folder isn't in my example output of what I want
so far I have this code:
function list-all() {
folderlist=()
for file in /home/USER/main/*; do
echo "$(basename "$file")"
done
}
it prints all the folder names in a vertical list like this:
folder1
folder2
folder3
folder4
template
from this output I want to get to this:
folder1
folder1
=======
contains:
* x
* y
* z
folder2
folder2
=======
contains:
* x
* y
* z
folder3
folder3
=======
contains:
* x
* y
* z
folder4
folder4
=======
contains:
* x
* y
* z
thanks a lot in advance!
cat main/*/description
?template
folder. see my example output.template
. Of course, you might argue thatcat
is not Bash.