delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/12/05/15:04:07

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:reply-to:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=tpbZMosD8ssc6SCB
ehrlAr/CfodNxYcG9PVbvPcKrzTR31kmttLYX14YGDazt/f6zl04NiUWFHMQfAxh
csYDD9/4OspEIQ0bhzOiWUpNdwipJG2/evEEHN9djj0Uu+yYwR87ofzprY079+CI
5ncG10Iy6Q7G11IbuUyQ/ReVFn0=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:reply-to:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=Ow9WKD/Z/dJ5XW+p5IUJ5G
tmOIY=; b=pzwddD9oT1SFp0STr0J4yvlOjBGDzfVP91hqP8Mt/vZvfnS6S0eLUF
WaqK0/jRndcMuPcr1dBByuiOqLzHJmeGXBs8kv+vJdRKCSuexy3b82iEfC2ZaToL
53f1Sz9mL4Y8T8C0S5zlKq0mmzSRkCNBWmUdb0x3jLPVqmGpZFkec=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
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
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 AT MX204CL04 DOT corp DOT emc DOT com>
To: cygwin AT cygwin DOT com
Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca
From: Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>
Message-ID: <e2de2246-20ad-308b-e6b1-20804163ef51@SystematicSw.ab.ca>
Date: Mon, 5 Dec 2016 13:03:40 -0700
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>
X-CMAE-Envelope: MS4wfIfsA1PekwjdBrv4ukwAFkpkNifxboqPaERaw41f7N3ovB5zN80eFxyOPjTg3/rEhUwgjuOwcbgCSPoM0N80Bpg55DS0bI6h4Fo5lV+5L2oaj1I61rbJ KkqaoracnlYg1LxPQbW+0NJM/FSXnWCyYoyZVK3xVbZjtYVPJZk/gJrtEY1DgMT6RrJufO8/ySucBQ==
X-IsSubscribed: yes

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019