If file = .cpp then print?

I'm trying to develop a script that makes it so only .cpp programs can print. I'm doing it for my computer programming class because everyone keeps printing the executable instead of the source code and it's wasting a lot of paper. How can I accomplish this? Thanks for the help. :smiley:

Only hunch I got is that CUPS can do filtering. Maybe research docs like Dissecting The CUPS Filtering System (ch 4, "The CUPS-internal filtering system": the MIME part could be a clue) or SDB:Using Your Own Filters to Print with CUPS - openSUSE.

Let me restate what I'd like to do. I want something like this:

if
file = .cpp
lp
else
print 'please only print the source file!'

What is the Unix shell translation? Thanks for the help thus far! It was my fault for not specifying.

So...Is there any way someone could please help me? :slight_smile:

Are they calling it as "lp <file>"? If so, and if you have Bash 3.0+, just place this earlier in the path than the real lp (or alias it, or... etc.):

#!/bin/bash

if [[ x"$1" =~ '.*\.cpp$' ]]; then
    /usr/bin/lp $1
else
    echo "Can't print $1, as it does not appear to be a source file."
fi

Amazing! Thanks! I'll try it!