From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36825 invoked by alias); 5 Dec 2016 23:30:30 -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 36774 invoked by uid 89); 5 Dec 2016 23:30:27 -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=disaster, Hx-spam-relays-external:shaw.ca, H*r:shaw.ca, 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.13) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Dec 2016 23:30:26 +0000 Received: from [192.168.1.100] ([174.0.238.184]) by shaw.ca with SMTP id E2iEcrwulOhJRE2iFc1S2W; Mon, 05 Dec 2016 16:30:24 -0700 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> <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com> To: cygwin@cygwin.com From: Brian Inglis Reply-To: Brian.Inglis@SystematicSw.ab.ca Message-ID: <0ac85458-01dd-7f0f-d6ad-25cbb672d785@SystematicSw.ab.ca> Date: Mon, 05 Dec 2016 23:30: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: <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 X-SW-Source: 2016-12/txt/msg00040.txt.bz2 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 -< 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