Chapter 13. Test This Command

The test command allows you to conditionally perform some task based on the existence, type, or status of a file. It also lets you do the same thing by comparing integer and string values. For my sake, we’ll keep it as simple as possible and stick to file tests while still showing off some of its potential.

You’ve Got Mail, or Do You?

OK. You’re not using AOL, but you want to know when you get mail. We can check for mail with the test command. Granted, a beep is not quite as nice as a human voice announcement, but it’s fine for our purposes.

The command below tests for the existence of /var/mail/username (that’s what the -e argument does) AND sounds a beep if it is found. At least it does if the beep program is installed ...

Get CLI for Noobies: A Primer on the Linux Command Line now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.