List Info

Thread: how to get pipes working




how to get pipes working
user name
2006-05-17 19:19:09
Here is a sample of code I have working in a shell script
and it works
find.
#!/usr/bin/ksh

x=x.o
y=y.o
nm $x | grep "main.*extern|entry.*CODE" >
/dev/null
if [ $? -eq 0 ] ; then
  echo "found main in $x" ;
else
  echo "$x does not have a main" ;
fi
nm $y | grep "main.*extern|entry.*CODE" >
/dev/null
if [ $? -ne 0 ] ; then
  echo "$y does not have a main" ;
else
  echo "found main in $y" ;
fi

x.o does contain the main and y.o does not.  It give the
correct
responses

Now when I put it into my makefile

##
## add a file to a archive
##
AR_ADD = $(NM) $$< | grep
"main.*extern|entry.*CODE" > /dev/null ; \
        if [ $$? -ne 0 ] ; then $(AR) $(AR_OPT) $$(LIB)
$$
> /dev/null
; fi

I get :
... ; /usr/bin/nm $< | grep
"main.*extern|entry.*CODE" > /dev/nu\
ll ; if [ $? -ne 0 ] ; then ar rv $(LIB) $ >
/dev/null ; fi
/bin/sh: Syntax error at line 1 : `|' is not expected.

I know it wasn't in the ... It worked fine until I put the
$(AR_ADD)
with the other commands


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
how to get pipes working
user name
2006-05-17 20:19:54
%% "PATTON, BILLY \(SBCSI\)" <BP1497att.com> writes:

  pb> Here is a sample of code I have working in a shell
script and it works
  pb> find.

  pb> #!/usr/bin/ksh

  pb> Now when I put it into my makefile

  pb> /bin/sh: Syntax error at line 1 : `|' is not
expected.

If it works in a script and fails in the makefile, then
99.99% of the
time it's going to be quoting issues.

The only real quoting issues in make are making sure
"$" is quoted
properly.

  pb> AR_ADD = $(NM) $$< | grep
"main.*extern|entry.*CODE" > /dev/null ; \
  pb>         if [ $$? -ne 0 ] ; then $(AR) $(AR_OPT)
$$(LIB) $$ > /dev/null ; fi

This is _NOT_ quoted properly.

Remember you're quoting "$" that you want to
PASS TO THE SHELL.  You
leave _unquoted_ "$" that you want MAKE TO
EXPAND before invoking the
shell.

Don't quote $<; $< is a make variable, so it must be
expanded before the
shell is invoked.

Similarly for $(LIB) and $.

  pb> I get :
  pb> ... ; /usr/bin/nm $< | grep
"main.*extern|entry.*CODE" > /dev/null ; if [
$? -ne 0 ] ; then ar rv $(LIB) $ > /dev/null ; fi

Yes!  This is the exact text make is sending to the shell!

If you take that text and put it in a script or on the
command line,
your shell will error out just as the one make does.

Try running just one bit:

    $ /usr/bin/nm $< | grep "foo"
    -bash: syntax error near unexpected token `|'

Hm!!!

Well, "<" is a special character to the
shell, that's why: it's input
redirection.

-- 
------------------------------------------------------------
-------------------
 Paul D. Smith <psmithgnu.org>          Find
some GNU make tips at:
 http://www.gnu.org        
             http://make.paulandlesl
ey.org
 "Please remain calm...I may be mad, but I am a
professional." --Mad Scientist


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )