Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to put together a simple script that will scan my home directory with clamscan and give me a warning if any viruses were found. What I have so far is:

#! /usr/bin/env bash

clamscan -l ~/.ClamScan/$(date +"%a%b%d") -ir /home
[ $RETVAL -eq 0 ] && notify-send 'clamscan finished. No viruses found'
[ $RETVAL -eq 1 ] && notify-send 'clamscan found a virus' && touch ~/Desktop/VirusFound
[ $RETVAL -eq 2 ] && notify-send 'clamscan encountered errors. Check the logs' && touch ~/Desktop/ClamscanError

find ~/.ClamScan/* -mtime +7 -exec rm {} \;

However, I'm unsure about a couple of things:

I'm always wary of using rm- as far as I can tell, the find command I've got should be deleting any log files that are more than a week old.

I'm also not entirely sure how the return value testing works- I've got a manual that briefly covers bash, which says that the meaning of $? is "match one character", and I'm not entirely sure how that grabs the return value. Should I be using -eq or = for testing the return value? From what I can tell -eq tests strings and = tests numerals, but I'm not sure what the type of the return value is.

share|improve this question
up vote 0 down vote accepted

If you'd like more info on bash you can type man bash to read the online manual.

-eq is the correct operator for testing if numbers are equal.

? (without the dollar sign) "Matches a single character" when doing filename pattern matching. $? is a Special Parameter that "Expands to the status of the most recently executed foreground pipeline" (for your purposes "foreground pipeline" just means command)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.