X-Recipient: archive-cygwin@delorie.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:from:reply-to:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=eNUIEu1ij0SZF0zj
	r6XO9iLbdew7EHA8hafP39qWaj/JWZp8UMfLSwny/+DISHxJB0NoCxGMDVv6cFHm
	uLHu54rkGt3F7+2v6STOXvYm18Xx2RkZGBsIHbipZA8N4bBRBgW/XqqSWj5pjleB
	c+RhLpUyyPwciI+NhQJs02gKmDY=
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:from:reply-to:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=34br+TfXJ5TbSFbMwdxLYH
	8+KOY=; b=t010z6wdK4O8w0tAsHU/ZWXH0V4R9a/yoqiJvBQ9iokPUywxqNFIhe
	AyW7GzOz47/oPBrNnxO0MLa20A+rpLmdMSHsLGVlJBU1GjHVEYH59GV4Vfg1MT7R
	TZodZVbxUA14rqJ++f6xbKORCLju6SWOPtMGTgQVFnexn9XSVzCh4=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.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=disaster, Hx-spam-relays-external:shaw.ca, H*r:shaw.ca, H*RU:shaw.ca
X-HELO: smtp-out-no.shaw.ca
X-Authority-Analysis: v=2.2 cv=T5n8d7CQ c=1 sm=1 tr=0 a=WqCeCkldcEjBO3QZneQsCg==:117 a=WqCeCkldcEjBO3QZneQsCg==:17 a=IkcTkHD0fZMA:10 a=Isn9AvQghXJh6S3JAWoA:9 a=QEXdDO2ut3YA:10
Subject: Re: sh -c and newline
References: <91DCAC3CB99C724EB365BB64677FBE7B1007BC@MX204CL04.corp.emc.com> <e2de2246-20ad-308b-e6b1-20804163ef51@SystematicSw.ab.ca> <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com>
To: cygwin@cygwin.com
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Reply-To: Brian.Inglis@SystematicSw.ab.ca
Message-ID: <0ac85458-01dd-7f0f-d6ad-25cbb672d785@SystematicSw.ab.ca>
Date: Mon, 5 Dec 2016 16:30:22 -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: <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-CMAE-Envelope: MS4wfPjvO04Tu/f+5KW1Iy4KsavrivWX4Yr1jkmsMLnKnwY+rfCR3iC70g5rALgWBMyV6UyOBL7DF5YAHS1JvmNLwc5q/3m1a9bhB+hpnTQ+Z+w4efwLBxsQ Wjg5umunjbaqsQ7PKZ2XPmOYgYA+92YRpMhCZLazwt+hHywbFsb+2W7Nf3DLs+BN0jmiIrynHw7XZg==
X-IsSubscribed: yes

On 2016-12-05 14:11, Gluszczak, Glenn wrote:
> On 2016-12-05 15:04, Brian Inglis wrote:
>> 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
> Thank you for the answer Brian. I was trying to show a problem with a
> HERE document and used echo but it is not the exact same issue.
> I forgot about the order of substitution; my original issue is
> similar.
> In CMD, you can't have multiple lines for sh -c but in shell you can
> sh -c "cat -<<EOF
> hello
> EOF"
> Turns out the newlines are being sent, but CMD thinks a command is
> only on one line. Perhaps there is a way to specify multiple lines in
> a cmd prompt.

Use can use & in cmd like ; in bash and && works the same in both; 
with conditional and loop constructs in cmd, you can use:
	if|for ... (	command1...
			command2...
		) 
across multiple lines, and you can use ^ in cmd like \ in bash for both 
line continuation and escaping.

Learned this stuff porting some shell scripts to cmd for use by folks 
on backup or home desktops during Disaster Recovery and migration backup 
tests, so they could download and prep data locally, in case any of the 
Unix or file servers, or network, to do this automatically and transparently 
were inaccessible.

-- 
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

