Task 03 — Replace tabs with 4 spaces, recursively
Write a script 03.sh that walks a directory tree and edits every regular file in place, replacing each tab character (\t) with four spaces.
Submit as
03.sh
Input
| Source | Format |
|---|---|
| CLI | ./03.sh <dir> — root directory to process |
| Filesystem | All regular files under <dir> recursively. Do not follow symlinks. File contents may contain arbitrary bytes/text. |
Output
| Stream | Format |
|---|---|
| stdout | Not checked (usually empty) |
| stderr | Not checked |
| Exit code | 0 on success |
| Side effect | Every regular file under <dir> is modified in place: each \t → four spaces (). No .bak files left behind. Running twice must be idempotent (second run changes nothing). |
Example
Before notes.txt:
hello world
indent
(\t shown as gaps above; real file contains tab characters.)
./03.sh .
After notes.txt:
hello world
indent
What the grader checks
- Exit code
0 - No tab characters remain anywhere under the tree (
grep -RP $'\t'finds nothing) - Spot-check: second line of
a/one.txtbecomes exactlyindent(four spaces, no tab)
Hints
find <dir> -type f— regular files onlysed -i 's/\t/ /g'per file; use-print0/xargs -0for safe names