1

I'm trying to create new folders with md files inside, and md files should have some text prepared inside. Problem is when folders have spaces in names. I have tried many different combinations with @, brackets and quotes but nothing worked.

This is current code:

#!/bin/bash

mkdir {folder1,folder2,'another folder'}

for f in $(ls -d -- */); do echo "---
tags: tag1, tag2
---" >> "$f"/mdfile.md; done
phidrho
  • 13

1 Answers1

2

There's no need to use ls there, or ever in a loop. The output of ls is exclusively for looking at.

#!/bin/bash

mkdir folder1 folder2 'another folder' 

for f in */; do
    cat >>"$f"/mdfile.md <<END
---
tags: tag1, tag2
---
END
done

Related:

Kusalananda
  • 333,661