cups-printing.txt - small error/fix

J.A. Neitzel jan at belvento.org
Wed Oct 3 22:25:20 PDT 2001


Hello Alex Kloss,

I was reading your hint and noticed a small thing that you may
want to fix.

In the "Ghostscript:" section ...
You have:
for file in src/*.c
do
  timeinc=`cat $file | grep time_.h`
  if [ -n "$timeinc" ]
    then
    mv $i $i.old
    cat $i.old | \
    sed $'/#include "time_.h"/a \\\n#include "time.h"' \
    > $i
  fi
done

First you use $file and then you switch to use $i . Running these
commands produces an error because $i contains nothing. The fix?
Well, you can choose either $file, or $i, and use it all the way
through. It will work fine then...

I, however, would recommend the following as an alternative, and
much simpler, method to achieve the same thing:
for i in src/*.c; do
    if grep time_.h $i >/dev/null; then
        mv $i $i.old &&
        sed $'/#include "time_.h"/a \\\n#include "time.h"' \
        $i.old > $i
    fi
done

Changes I made and why? Well, you used cat to pipe to grep and/or
sed . Using cat is not required here. Just grep or sed the file
directly is more efficient. Also, instead of assigning the output
of the grep to a variable and then testing for NULL, you can simply
use the return value from grep .

If grep finds "time_.h", it returns 0 (success). Just more efficient
and a little less typing for the hint reader too.
...

I know that these might simply be personal preferences why you did
it this way. I just saw that perhaps my observations could be
helpful in some way. Take it as you will =)
-- 
Cheers,
Jeffrey Allen Neitzel
Linux locutus 2.4.10 #1 Tue Oct 2 15:04:46 EST 2001 i686



More information about the hints mailing list