Problem with running lint

This is a strange problem that I can't figure out - I run lint on my C programs to weed out unused variables. The output can be quite large, so I use sed to cut out just unused variables section. The typical command looks like this:

 lint -I /usr/local/include  -I./include -m hn.c
 

As my includes can be in different places I put together a small script to build the proper -I directivesf or lint. When I run the script somehow lint can not follow -I directive. See the script below, I added echo just to show the command to be executed. When I cut/paste the command it runs without any issue:

 #!/bin/ksh
 INCL="-I /usr/local/include ";
if [ -d include ]; then
        INCL="${INCL} -I./include"; 
elif [ -d ../include ]; then
        INCL="${INCL} -I../include"; 
fi
 echo "COMMAND: " lint "${INCL}" -m "$1";
echo;
 lint "${INCL}" -m "$1" | sed -n '/variable unused/,/^$/p'
 

This is the example input for the lint:

 
 $ ls *.c include 
hn.c
 include:
hn1.h
  
 $ cat include/hn1.h 
#define MAX_SZ 1024
  
 #include <hn1.h>
 static  double  arr[MAX_SZ];
static  double  k = 1.0;
 
double  get_hn1()
{
  int           i, n;
  double        tot = 0;
         for(i = 0; i < MAX_SZ; i++)
        {
                tot += k * arr;
        }
        return(tot);
}
 

When I run the script, it can't see the hn1.h

 $ ./lnt hn.c
COMMAND:  lint -I /usr/local/include  -I./include -m hn.c
 "hn.c", line 1: error: cannot find include file: <hn1.h>
variable unused in function
lint: errors in hn.c; no output created
lint: pass2 not run - errors in hn.c
    (9) n in get_hn1
 

Now I cut/paste the command from above:

 $ lint -I /usr/local/include  -I./include -m hn.c
 variable unused in function
    (9) n in get_hn1
 name defined but never used
    get_hn1             hn.c(8)
 

Any idea why lint is not happy within the script?

I think you are quoting a little too aggressively. Try ${INCL} instead of "${INCL}" to let it split on spaces instead of cramming it into lint as one giant argument.

To see the difference, try printf "%s\n" "${INCL}" vs printf "%s\n" ${INCL}

You are right, removing double quotes around ${INCL} helped. Puzzle solved. Thank you!

I don't know how to tag it as solved.

1 Like

Look at the top of every page in any thread you start. You will see the words "Edit Tags". Select those words to edit the tags for your thread (including the "solved" tag).

I have added the tags "lint" and "solved" to this thread for you.

1 Like