Signal9Signal9 — home
online
back to labs

Conditionals: Does the File Exist?

EasyShell Scripting10-20 min
The brief

Scripts make decisions with if. The test [ -f PATH ] is true when PATH is an existing regular file.

Write /root/scripts/check.sh that prints 'present' if /root/data/config.ini exists and 'absent' if it doesn't. The file has been seeded for you, so a correct script prints:

present

Structure: if [ -f /root/data/config.ini ]; then echo present; else echo absent; fi. Grading runs your script with the file present and checks it prints 'present', then runs it again with /root/data emptied so config.ini is gone and checks it prints 'absent' — so test for the file rather than printing a fixed word; the else branch is what makes it a real conditional.

What you'll do
  • Use if [ -f ... ] to test for the file
  • Print 'present' when it exists, 'absent' otherwise

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.