bash can change a value as it puts it in the line:
| You write | Does |
|---|---|
${v%.txt} | Cuts .txt off the end |
${v// /-} | Puts - in place of every space |
text
learner@reef:~$ f="hot cross bun.txt"
learner@reef:~$ echo "${f%.txt}"
hot cross bun
learner@reef:~$ echo "${f// /-}"
hot-cross-bun.txt
learner@reef:~$ echo "$f"
hot cross bun.txt ← f itself stays the sameBefore the logs are emptied, Ana wants a copy of each, named with no spaces. Write ~/stamp.sh. For each .log file in ~/logs, it writes the log's name:
text
learner@reef:~$ ./stamp.sh
cake case fridge
door
registerThen it copies the log to ~/archive: cake-case-fridge.log, door.log, register.log.
- Write it with
nano ~/stamp.sh:cd ~/logs, then a loop over*.logthat writes each name without.log. - Make it runnable with
chmod u+x ~/stamp.sh, then run./stamp.sh. - Make
~/archivewithmkdir -p, and copy each log there with-for every space.
Objectives
- Write each log's name, without
.log. - Copy each log to
~/archive, with-for every space.