csot/contest

Task 04 — Rename *.txt to *.md

Write a script 04.sh that recursively renames every file whose name ends in .txt so it ends in .md instead. Other files and the directory layout stay unchanged.

Submit as

04.sh

Input

Source Format
CLI ./04.sh <dir> — root directory to process
Filesystem Tree under <dir>. Only regular files whose basename ends with .txt are renamed (suffix .txt.md). Files like intro.bak, readme.md, image.png are untouched.

Output

Stream Format
stdout Not checked (usually empty)
stderr Not checked
Exit code 0 on success
Side effect Renames on disk only. Example: docs/readme.txtdocs/readme.md. No .txt files remain under <dir>.

Example

Before:

docs/
├── readme.txt
├── notes/
│   ├── intro.txt
│   └── intro.bak
└── sub/
    └── spec.txt
./04.sh docs

After:

docs/
├── readme.md
├── notes/
│   ├── intro.md
│   └── intro.bak
└── sub/
    └── spec.md

What the grader checks

  • Exit code 0
  • Zero files matching *.txt under the tree
  • Expected .md files exist at the renamed paths
  • Non-.txt files (e.g. .bak, .png) still present

Hints

  • find … -name '*.txt'
  • ${name%.txt}.md — safe rename; handle spaces with find -print0

Points: 5

Other tasks