Hands-on task
This task is step 5 of the course “Your first bash script”
if: does the file exist
Write the script /root/check-file.sh. It takes a path as its first argument and prints exists if there's a regular file at that path, and missing if there's nothing there or it's a directory.
$ bash check-file.sh /etc/hostname
exists
$ bash check-file.sh /etc
missing
$ bash check-file.sh /no/such/file
missing
With no argument it prints missing too.
Reference:Conditions and loops
What you'll practise:
- bash scripts
- if
- test
- file tests