From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97907 invoked by alias); 5 Dec 2016 20:03:53 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 97813 invoked by uid 89); 5 Dec 2016 20:03:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=Hx-spam-relays-external:shaw.ca, H*r:shaw.ca, HX-HELO:sk:smtp-ou, H*RU:shaw.ca X-HELO: smtp-out-no.shaw.ca Received: from smtp-out-no.shaw.ca (HELO smtp-out-no.shaw.ca) (64.59.134.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Dec 2016 20:03:42 +0000 Received: from [192.168.1.100] ([174.0.238.184]) by shaw.ca with SMTP id DzUCctUs9cWiHDzUDcwNtY; Mon, 05 Dec 2016 13:03:41 -0700 X-Authority-Analysis: v=2.2 cv=JLBLi4Cb c=1 sm=1 tr=0 a=WqCeCkldcEjBO3QZneQsCg==:117 a=WqCeCkldcEjBO3QZneQsCg==:17 a=IkcTkHD0fZMA:10 a=w5aJ8kaLLAry8Qfnm_kA:9 a=QEXdDO2ut3YA:10 Subject: Re: sh -c and newline References: <91DCAC3CB99C724EB365BB64677FBE7B1007BC@MX204CL04.corp.emc.com> To: cygwin@cygwin.com Reply-To: Brian.Inglis@SystematicSw.ab.ca From: Brian Inglis Message-ID: Date: Mon, 05 Dec 2016 20:03:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <91DCAC3CB99C724EB365BB64677FBE7B1007BC@MX204CL04.corp.emc.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfIfsA1PekwjdBrv4ukwAFkpkNifxboqPaERaw41f7N3ovB5zN80eFxyOPjTg3/rEhUwgjuOwcbgCSPoM0N80Bpg55DS0bI6h4Fo5lV+5L2oaj1I61rbJ KkqaoracnlYg1LxPQbW+0NJM/FSXnWCyYoyZVK3xVbZjtYVPJZk/gJrtEY1DgMT6RrJufO8/ySucBQ== X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00039.txt.bz2 On 2016-12-05 12:38, Gluszczak, Glenn wrote: > I can't seem to get sh -c to recognize newline. Tcsh -c works. > I'm using echo as an example but I'm actually trying to build a > here-document. > %%%sh -c "echo \nhello" > nhello > %%%sh -c "echo \\nhello" > nhello > %%%sh -c "echo \\\nhello" > \nhello > %%%tcsh -c "echo \nhello" > nhello > %%%tcsh -c "echo \\nhello" > \nhello > %%%tcsh -c "echo \\\nhello" > hello Your login shell is scanning and interpreting escapes in the input, then the subshell you are running, so you need to quote \n to let echo see it. Builtin echo does not recognize escapes without -e. You can use echo -e, or $ prefix a single quoted string to have the shell interpret the escape sequence. $ sh -c "echo -e '\nhello'" hello $ sh -c "echo $'\n'hello" hello $ sh -c "echo $'\nhello'" hello -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple