This is strange...

Maarten Litmaath maart at cs.vu.nl
Thu Dec 22 19:59:33 AEST 1988


mcapron at ektools.UUCP (M. Capron) writes:
\#!/bin/sh
\for i in *.c
\do
\#Place a list of include files in $incs seperated by spaces.
\#CODE A or CODE B goes here.
\	echo "$i : $incs"
\done

\CODE A: This works.
\incs=`egrep '^#[ 	]*include[ 	]*"' $i | awk '{printf "%s ", $2}'`
\incs=`echo "$incs" | sed 's/"//g'`

\CODE B: This does not work.
\incs=`egrep '^#[ 	]*include[ 	]*"' $i | awk '{printf "%s ", $2}' |
	sed 's/"//g'`

Compare your example with the following:

	% echo -n 'merry Xmas' | sed 's/.*/&, happy new year/'
	%

Now get rid of the `-n' and suddenly everything works! The problem: sed won't
do anything with unfinished lines! You explicitly didn't append a newline in
the awk script. See how far that got you! :-)
Solution:

	incs=`egrep '^#[ 	]*include[ 	]*"' $i |
		awk '       {printf "%s ", $2}
			END {printf "\n"}' |
		sed 's/"//g'`

BTW, it's not forbidden to use newlines between backquotes!
Another interesting case:

	$ cat > merry_Xmas
	happy
	1989
	$ card=`cat merry_Xmas`
	$ echo $card
	happy 1989
	$ echo "$card"
	happy
	1989

Csh hasn't got this anomaly.
-- 
if (fcntl(merry, X_MAS, &a))          |Maarten Litmaath @ VU Amsterdam:
        perror("happy new year!");    |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.wizards mailing list