From owner-freebsd-questions@FreeBSD.ORG Fri Mar 13 09:30:14 2009 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EE4211065673 for ; Fri, 13 Mar 2009 09:30:14 +0000 (UTC) (envelope-from nvass9573@gmx.com) Received: from mail.gmx.com (unknown [213.165.64.42]) by mx1.freebsd.org (Postfix) with SMTP id 5204F8FC0A for ; Fri, 13 Mar 2009 09:30:14 +0000 (UTC) (envelope-from nvass9573@gmx.com) Received: (qmail invoked by alias); 13 Mar 2009 09:30:12 -0000 Received: from adsl73-179.ath.forthnet.gr (EHLO [192.168.1.5]) [77.49.4.179] by mail.gmx.com (mp-eu005) with SMTP; 13 Mar 2009 10:30:12 +0100 X-Authenticated: #46156728 X-Provags-ID: V01U2FsdGVkX1/SX/sS057S1x92/GhEF1RwthAeG+4AGvKCXJylaU +hjWTo0SVJzVZT Message-ID: <49BA278D.5080800@gmx.com> Date: Fri, 13 Mar 2009 11:29:49 +0200 From: Nikos Vassiliadis User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: David Banning References: <20090312173436.GA51898@skytracker.ca> In-Reply-To: <20090312173436.GA51898@skytracker.ca> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.62 Cc: questions@freebsd.org Subject: Re: sed error "unescaped newline inside substitute pattern" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2009 09:30:15 -0000 David Banning wrote: > Here is the php line that gives the error; > > cat start_text | sed "s/--maintext--/$test/" > endtext > > give error; > > sed: 1: "s/--maintext--/ Comment ...": unescaped newline inside substitute pattern > > where $test contains customer input from a website form > > There is something about the content of the text within the variable $test that is causing the error. > > Any pointers would be helpful. You cannot use unescaped newlines in the replacement string: # sed 's/foo/foo<<>> > bar/' sed: 1: "s/foo/foo bar/": unescaped newline inside substitute pattern You have to precede each newline character with a backslash: # sed 's/foo/foo\<<>> > bar/' foo foo bar The examples above are made using the bourne shell. The above doesn't work in csh. It's the documented behavior: 2. The escape sequence \n matches a newline character embedded in the pattern space. You cannot, however, use a literal newline character in an address or in the substitute command. ... A line can be split by substituting a newline character into it. To specify a newline character in the replacement string, precede it with a backslash. I am sure there is some good reason behind this... OT, you should not pass parameters to shell scripts using double quotes, since the shell will evaluate possible variable values: # echo "$OSTYPE" FreeBSD # echo '$OSTYPE' $OSTYPE I really doubt you want the first behavior, that is, variable evaluation for strings coming from a web server. HTH, Nikos