[NTLUG:Discuss] dealing with backslashes '\' when 'read'ing files..

Kenneth Loafman kenneth at loafman.com
Sat Feb 18 05:46:01 CST 2006


They are called 'continuation lines'.  Common in most languages, but 
there is one caveat.  A \ at the end of the line will continue the line, 
but a '\ ' (backslash, space), will be treated as an error.  Hard to 
spot visually.

...Ken


Richard Geoffrion wrote:
> Error: Makefile:184: *** missing separator.  Stop.
> 
> --my take on the issue based on my research--
> 
> ----
> 
> What do you call those multi-line bash lines \
> that continue on the next line so that\
> there aren't long lines in the editor?
> 
> I don't know what to Google and need help finding search terms or solutions.
> 
> Issue:  Script parses a Makefile line-by-line searching to remove a string
> but gets tripped up when encountering those baskslashed end of line lines.
> 
> Script-so-far:
> 
> #!/bin/bash -x
> rm Makefile.new #debug line to keep makefile clean during runs
> while read LINE; do
> if echo "$LINE" | grep -q "\ /usr/include/sys/stdsyms.h"  ; then
>         NEWLINE=`echo $LINE | sed s#/usr/include/sys/stdsyms.h##g`
>         echo -e "$NEWLINE" >> Makefile.new
> else
>         echo -e "$LINE" >> Makefile.new
> fi
> done < Makefile
> #mv Makefile.new Makefile
> 
> The Original Makefile: (a few sample lines in question)
> MP_OTHER_OBJS = mpeg.o subsample.o param.o rgbtoycc.o \
>         readframe.o combine.o jrevdct.o frame.o fsize.o frametype.o \
>         libpnmrw.o specifics.o rate.o opts.o
> MP_OTHER_SRCS = mpeg.c subsample.c param.c rgbtoycc.c \
>         readframe.c combine.c jrevdct.c frame.c fsize.c frametype.c \
>         libpnmrw.c specifics.c rate.c opts.c
> 
> RESULTING FILE AFTER RUN???
> 
> Well.. those  6  lines become two and they contain [tabs].   How do you get
> read to not concatenate those multi-lines?
> 
> Is there a different approach I should be taking?
> 





More information about the Discuss mailing list