Split Paths Without Calling basename
Write /home/student/bin/pathinfo.sh. For each path given as an argument, it prints one line:
<dir>|<base>|<name>|<ext>
| Part | Meaning |
|---|---|
dir | everything before the last /, or . when there is no / |
base | everything after the last / |
name | base without its extension |
ext | the part after the last dot of base, without the dot; empty when there is none |
A file name that starts with a dot and has no other dot (.bashrc) has no extension. Examples:
$ pathinfo.sh /var/log/app.log.gz report.pdf /etc/.bashrc "dir with space/file"
/var/log|app.log.gz|app.log|gz
.|report.pdf|report|pdf
/etc|.bashrc|.bashrc|
dir with space|file|file|
Use only bash itself to take the paths apart (no basename, dirname, sed, awk or cut).
About this machine
Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.
Part of Shell Scripting for Automation. Next step: The Counter That Always Says Zero
Teaching or writing about this? Embed this lab on your page
Your machine is ready to start
A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.
No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.